|
-
Dec 11th, 2002, 04:44 AM
#1
Thread Starter
Lively Member
Dynamic Control Fill...[SOLVED]
I want to fill some Controls with information I read from a file...
The text is stored as:
Formname | ControlName | Value
eg.
Form1|Text1|Textvalue
When I run my code I get a `invalid qualifier`- error...
so theres something miss in the syntax...
it should give me
Form1.Text1 = Textvalue
VB Code:
Open FileName For Input As #fnum
Do Until EOF(1)
Line Input #fnum, data
If Not data = "" Then
elements = Split(data, "|")
'MsgBox elements(UBound(elements) - 2) & "-" & elements(UBound(elements) - 1) & "-" & elements(UBound(elements))
elements(UBound(elements) - 2).elements(UBound(elements) - 1) = elements(UBound(elements))
End If
Loop
Last edited by Chrissie; Dec 13th, 2002 at 04:14 AM.
-
Dec 11th, 2002, 05:44 AM
#2
Thread Starter
Lively Member
VB Code:
Forms(elements(UBound(elements) - 2)).Controls(elements(UBound(elements) - 1)) = elements(UBound(elements))
I guess this is better...but it gives me back a Error 13...when running the code..
-
Dec 11th, 2002, 05:51 AM
#3
Hyperactive Member
hi
check whether you place all text boxes correctly on form and also check form names with data.
-
Dec 11th, 2002, 07:47 AM
#4
Thread Starter
Lively Member
Yeah I checked that already...
When I run this it works perfect...so I doubt wether my code in my last post is correct...
VB Code:
Form1.Text1 = "Textvalue"
When I read the following line using the code stated above...
Form1|Text1|Textvalue
It gives me..."Type Mismatch" - Error 13
-
Dec 12th, 2002, 10:01 AM
#5
Thread Starter
Lively Member
-
Dec 12th, 2002, 11:58 AM
#6
If you are filling the default properties, then this should work.
VB Code:
Option Explicit
Private Sub Command1_Click()
Dim Data As String
Dim Elements() As String
Dim ctl As Control
Dim frm As Form
Open "c:\test.txt" For Input As #1
Do Until EOF(1)
Line Input #1, Data
If Not Data = "" Then
Elements = Split(Data, "|")
For Each frm In Forms
If frm.Name = Elements(0) Then
Exit For
End If
Next frm
For Each ctl In frm.Controls
If ctl.Name = Elements(1) Then
ctl = Elements(2)
Exit For
End If
Next ctl
End If
Loop
Close #1
End Sub
-
Dec 12th, 2002, 12:32 PM
#7
Addicted Member
Also, you might try:
trim(elements(ubound(elements)-2)).trim(elements(ubound(elements) -1)) = trim(elements(ubound(elements)))
JS
Disclaimer:
* The preceding message was in no means meant to be critical, mean spirited, insincere, or facetious.
Disclaimer for disclaimer:
The preceding disclaimer may in fact be facetious in nature.
Thanks,
Jim
-
Dec 12th, 2002, 12:39 PM
#8
Originally posted by Sully
Also, you might try:
trim(elements(ubound(elements)-2)).trim(elements(ubound(elements) -1)) = trim(elements(ubound(elements)))
JS
The problem with this approach is the elements are being returned as strings and can not be converted to objects.
-
Dec 12th, 2002, 12:43 PM
#9
Addicted Member
You are correct Sir, I was just looking at that...but I think you should include the trim function in the if structures in your code above.
JS
Last edited by Sully; Dec 12th, 2002 at 01:01 PM.
Disclaimer:
* The preceding message was in no means meant to be critical, mean spirited, insincere, or facetious.
Disclaimer for disclaimer:
The preceding disclaimer may in fact be facetious in nature.
Thanks,
Jim
-
Dec 13th, 2002, 02:52 AM
#10
Thread Starter
Lively Member
What if I have this info stored in the file...won't fill in the control arrays.
frmInput|Text4(1)|Text4 - 1
frmInput|Text4(0)|Text4 - 3
-
Dec 13th, 2002, 04:13 AM
#11
Thread Starter
Lively Member
WOHOO! Got it finally working!!
Thanks for all your help..
VB Code:
Private Sub Command1_Click()
Dim Data As String
Dim Elements() As String
Dim ctl As Control
Dim frm As Form
Dim indexElements As String
Open "C:\Data.txt" For Input As #1
Do Until EOF(1)
Line Input #1, Data
If Not Data = "" Then
Elements = Split(Data, "|")
indexElements = ""
If Right(Elements(1), 1) = ")" Then
indexElements = Replace(Right(Elements(1), 2), ")", "")
Elements(1) = Left(Elements(1), (Len(Elements(1)) - 3))
End If
For Each frm In Forms
If frm.Name = Elements(0) Then
Exit For
End If
Next frm
For Each ctl In frm.Controls
If ctl.Name = Elements(1) Then
If indexElements = "" Then
ctl = Elements(2)
Exit For
Else
If ctl.Index = indexElements Then
ctl = Elements(2)
Exit For
End If
End If
End If
Next ctl
End If
Loop
Close #1
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|