Consulting

Results 1 to 4 of 4

Thread: Solved: label.caption take text from file

  1. #1
    VBAX Mentor
    Joined
    Dec 2009
    Posts
    416
    Location

    Solved: label.caption take text from file

    Hello (second time from today)

    I would like to add some texts in label(i).caption via an text file whit an marker that will tell from were to were to be fill the label
    label1.caption = "text.file-|-this one to be like an marker"
    label2.caption = "text.file-|-this one to be like an marker"
    .
    .
    .
    label20.caption = "text.file-|-this one to be like an marker"
    etc

    thx.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I would use an XML file

    [vba]

    <?xml version="1.0" encoding="utf-8"?>
    <app="myApp">

    <userform name="myForm">

    <control type="label"
    name="label1"
    caption"text.file-|-this one to be like an marker" />

    <control type="label"
    name="label2"
    caption"text.file-|-this one to be like an marker" />

    ....

    <control type="label"
    name="label20"
    caption"text.file-|-this one to be like an marker" />
    </userform>
    </app>
    [/vba]

    parsing it is a doddle
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor
    Joined
    Dec 2009
    Posts
    416
    Location
    and without xml?
    something like this?
    [VBA]
    InputData = Split(data(i - 1), Chr(13))
    For Each t In InputData
    If Len(t) > 0 Then _
    Me.Controls("label" & i).caption Application.Substitute(t, Chr(10), "")
    Next
    [/VBA]
    the reason is that I have all the input data in one file (data for combobox, for the date that to be inserted in rows in columns) and I would like to be the same with the label.caption

  4. #4
    VBAX Mentor
    Joined
    Dec 2009
    Posts
    416
    Location
    [VBA]
    Set f = fs.GetFile(ActiveWorkbook.Path & "\meniu.dutch")
    Open ActiveWorkbook.Path & "\meniu.dutch" For Input As #nFile
    Do While Not EOF(nFile)
    Input #nFile, sTemp
    For i = 10 To 80
    If Len(sTemp) > 0 Then
    nEqualsSignPos = InStr(sTemp, "=")
    nEqualsSignPos = nEqualsSignPos + 1
    If InStr(sTemp, "lab" & i) Then
    Controls("Label" & i).Caption = Mid(sTemp, nEqualsSignPos)
    End If
    End If
    Next
    Loop
    Close nFile

    [/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •