To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Article :: Building Dynamic Systems with Expressions in .NET
How Is XML Like An Interface?
Understanding Covariance and Contravariance
Print VS 2010 Keyboard Shortcut References in Letter (8.5x11in) and A4 (210×297mm) Sizes
Updated Productivity Power Tools



Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier

Reply Post New Thread
 
Thread Tools Display Modes
Old May 26th, 2005, 02:20 PM   #1
rdcody
Addicted Member
 
Join Date: Aug 00
Posts: 152
rdcody is an unknown quantity at this point (<10)
Question Reading form text file (RESOLVED)

Hey all,

I am having trouble trying to read/write to/from a text file to/from multiple
text boxes.

What I would like to do is write each texbox to a seperate line in a text file
like this...

Text1 - line #1
Text2 - line #2
Text3 - line #3
and so on...

and then I would like to read each line into a different textbox, like this...

line #1 - Text1
line #2 - Text2
line #3 - Text3


Any help would be appreciated,
Ron

Last edited by rdcody; May 27th, 2005 at 04:58 PM.
rdcody is offline   Reply With Quote
Old May 26th, 2005, 02:27 PM   #2
sciguyryan
Frenzied Member
 
sciguyryan's Avatar
 
Join Date: Sep 03
Location: Wales
Posts: 1,749
sciguyryan has a spectacular aura about (150+)sciguyryan has a spectacular aura about (150+)
Re: Reading form text file

To read try something like this:

VB Code:
  1. Dim intFree As Integer
  2. Dim strReadText As String
  3. Dim strTextLines() As String
  4. intFree = FreeFile
  5. Open "C:\SomeFile.txt" For Binary As #intFree
  6.     strReadText = Space$(LOF(intFree))
  7.     Get #intFree, , strReadText
  8. Close #intFree
  9. ' Create array of text lines from the file...
  10. strTextLines = Split(strReadText, vbNewLine)
  11. Text1.Text = strTextLines(0) ' First line...
  12. Text2.Text = strTextLines(1) ' Second line...
  13.  

And to write try the follwoing...

VB Code:
  1. Dim strMyText As String
  2. strMyText = Text1.text & vbNewLine & Text2.Text & vbNewLine & Text3.Text ' Etc.
  3. Dim intFree As Integer
  4. intFree = FreeFile
  5. Open fileName For Binary Access Write As #intFree
  6.     Put #intFree, , strMyText
  7. Close #intFree

Cheers,

RyanJ
__________________
My Blog.

Ryan Jones.
sciguyryan is offline   Reply With Quote
Old May 26th, 2005, 03:02 PM   #3
rdcody
Addicted Member
 
Join Date: Aug 00
Posts: 152
rdcody is an unknown quantity at this point (<10)
Re: Reading form text file

Hey sciguyryan,

Thanks for the quick reply.

On this line...

VB Code:
  1. strTextLines = Split(strReadText, vbNewLine)

I get an "Can't assign to array" error. Any Ideas? By the way I'm using VB5.

Thanks,
Ron
rdcody is offline   Reply With Quote
Old May 26th, 2005, 03:25 PM   #4
sciguyryan
Frenzied Member
 
sciguyryan's Avatar
 
Join Date: Sep 03
Location: Wales
Posts: 1,749
sciguyryan has a spectacular aura about (150+)sciguyryan has a spectacular aura about (150+)
Re: Reading form text file

Quote:
Originally Posted by rdcody
Hey sciguyryan,

Thanks for the quick reply.

On this line...

VB Code:
  1. strTextLines = Split(strReadText, vbNewLine)

I get an "Can't assign to array" error. Any Ideas? By the way I'm using VB5.

Thanks,
Ron
Hmm, I am afraid I do not use VB5 and so, am unable to test that....

I'll see if I can check if it can be done that way in VB5

Cheers,

RyanJ
__________________
My Blog.

Ryan Jones.
sciguyryan is offline   Reply With Quote
Old May 26th, 2005, 03:39 PM   #5
|2eM!x
Admodistrator
 
|2eM!x's Avatar
 
Join Date: Jan 05
Posts: 3,900
|2eM!x has a spectacular aura about (150+)|2eM!x has a spectacular aura about (150+)
Re: Reading form text file

check the codebank, posted by manavo like 5 days ago
__________________
|2eM!x is offline   Reply With Quote
Old May 26th, 2005, 03:42 PM   #6
sciguyryan
Frenzied Member
 
sciguyryan's Avatar
 
Join Date: Sep 03
Location: Wales
Posts: 1,749
sciguyryan has a spectacular aura about (150+)sciguyryan has a spectacular aura about (150+)
Re: Reading form text file

Quote:
Originally Posted by |2eM!x
check the codebank, posted by manavo like 5 days ago
ARGH! Damn my memory... Its not my fault - I blame the exams

Thanks for that - I wound have been here for hours looking otherwise

Cheers,

RyanJ
__________________
My Blog.

Ryan Jones.
sciguyryan is offline   Reply With Quote
Old May 26th, 2005, 04:02 PM   #7
rdcody
Addicted Member
 
Join Date: Aug 00
Posts: 152
rdcody is an unknown quantity at this point (<10)
Re: Reading form text file

Well...I'll be damned if I can find it...
rdcody is offline   Reply With Quote
Old May 26th, 2005, 04:11 PM   #8
rdcody
Addicted Member
 
Join Date: Aug 00
Posts: 152
rdcody is an unknown quantity at this point (<10)
Re: Reading form text file

Are you guys talking about the split function by manavo11? I have that,
but I still get the same error. Any ideas?
rdcody is offline   Reply With Quote
Old May 26th, 2005, 07:07 PM   #9
seraphicmortal
Member
 
seraphicmortal's Avatar
 
Join Date: May 05
Posts: 56
seraphicmortal is an unknown quantity at this point (<10)
Smile Re: Reading form text file

Hi RD Cody! I had that kind of program as well.. why don't you give this a try.. These codes saves the text being inputted by the user in the textbox in a file (which the file extension can btw be specified by you) and the user can retrieve the file and show the same text and order back to the form where your textboxes are... Quite a long explanation eyh.. You can tweek it to suit your needs if you want.

I made a class, which I named namelist.
This class has properties namely:
name
symbol
quantity

My example.plp output would look like this when opened in a text editor(like notepad):
[Name] x32
[Quantity] x75
[Symbol] q21


(globalvar.bas)
VB Code:
  1. Option Explicit
  2. Public pl1 As New namelist

(frm_field) 'This is the form where the textboxes are
VB Code:
  1. Option Explicit
  2. Private Sub fieldupload()
  3.     With pl1
  4.         .symbol = txt_sym.Text
  5.         .name = txt_name.Text
  6.         .quantity = txt_qty.Text
  7.     End With
  8. End Sub
  9. Private Sub cmd_apply_Click()
  10.     If Len(txt_sym.Text) = 0 Or _
  11.        Len(txt_name.Text) = 0 Or _
  12.        Len(txt_qty.Text) = 0 Or _
  13.         MsgBox "please enter the necessary values."
  14.         txt_sym.SetFocus
  15.     Else
  16.         fieldupload
  17.         MsgBox ("Creating profile...  Please choose what directory to save your profile.")
  18.         frm_dir.Caption = "Save Profile"
  19.         frm_dir.Show vbModal
  20.     End If
  21. End Sub
  22. Function GetString(tmpStr As String, tmpDiv As String, Mode As String) As String
  23. Dim tmpRetStr As String
  24. Dim tmpLen As Integer
  25. Dim tmpErr As Integer
  26.   ' *****************************************************
  27.   ' tmpString = The whole string
  28.   ' tmpDiv = The Divider chr
  29.   ' if mode = "F" then get the string in front of the div
  30.   '
  31.   ' Return values:
  32.   '  Errors
  33.   '    Err1 = wrong mode
  34.   '    Err2 =  No Div, did not found a divider
  35.   '    Err5 = No String
  36.   '    Err6 = No C, did not find any string in the middle
  37.   '  Normal
  38.   '    String
  39.   ' ******************************************************
  40.   ' Example: GetString("Red=Green","=","F") will retrun "Red"
  41.   ' *** for string
  42.   tmpErr = 0
  43.   If Len(tmpStr) = 0 Then
  44.     tmpErr = 5
  45.     GoTo GetStringErr
  46.   End If
  47.  
  48.   ' *** test for chr in tmpDiv
  49.   If Len(tmpDiv) = 0 Then
  50.     tmpErr = 2
  51.     GoTo GetStringErr
  52.   End If
  53.   ' *** test for div in string
  54.   If InStr(1, tmpStr, tmpDiv) = 0 Then
  55.     tmpErr = 2
  56.     GoTo GetStringErr
  57.   End If
  58.  
  59.   If Mode = "C" Then
  60.      tmpRetStr = Mid(tmpStr, 9)
  61.      If Len(tmpRetStr) > 0 Then
  62.          GetString = tmpRetStr
  63.          Exit Function
  64.      Else
  65.          tmpErr = 6
  66.          'GoTo GetStringErr
  67.          MsgBox ("Error: Non-standard format in saving profile name.  No hyphen '-' found.")
  68.          frm_dir.txt_plprofile.Text = "*.plp"
  69.      End If
  70.          MsgBox ("Error: Non-standard format in saving profile name.  No hyphen '-' found.")
  71.          frm_dir.txt_plprofile.Text = "*.plp"
  72.   End If
  73.     tmpErr = 1
  74.     frm_dir.txt_plprofile.Text = "*.plp"
  75.     'GoTo GetStringErr
  76.   Exit Function
  77. GetStringErr:
  78. GetString = "Err" & tmpErr
  79. End Function
  80. Private Sub loadfield()
  81.     txt_sym.Text = pl1.symbol
  82.     txt_name.Text = pl1.name
  83.     txt_qty.Text = pl1.quantity
  84. End Sub
  85.    
  86. Private Sub cmd_back_Click()
  87.     Form_Load
  88.     Me.Hide
  89.     frm_loadfile.Show vbModal
  90. End Sub
  91. Private Sub cmd_next_Click()
  92.     Me.Hide
  93.     frm_summary.Show vbModal ' another form which basically are just labels that shows a summmay of the information
  94. End Sub
  95. Private Sub cmd_retrieve_Click()
  96.     frm_dir.file1.Enabled = True
  97.     loadfield
  98.    
  99.     frm_dir.Caption = "Load Profile"
  100.     frm_dir.Show vbModal
  101. End Sub
  102. Private Sub Form_Load()
  103. On Error GoTo Form_Load_Error
  104. 'This code sets up the Text Boxes
  105.     cmd_next.Enabled = False
  106.     Me.txt_name.Text = ""
  107.     Me.txt_qty.Text = ""
  108.     Me.txt_sym.Text = ""
  109. On Error GoTo 0
  110. Exit Sub
  111. Form_Load_Error:
  112. MsgBox "Error " & Err.Number & " (" & Err.description & ") in procedure Form_Load of Form " & Me.Name
  113. End Sub
  114. Private Sub Validate_Entry(ByRef txtBox As TextBox)
  115.     If Left$(txtBox.Text, 1) <> vbNullString Then
  116.         If UCase(txtBox.Text) Like "[A-Z]" & String(Len(txtBox.Text) - 1, "#") And Len(txtBox.Text) < 6 Then
  117.             txtBox.Text = UCase(txtBox.Text)
  118.             txtBox.SelStart = Len(txtBox.Text)
  119.         Else
  120.             MsgBox "Please try again.", vbOKOnly + vbInformation, "Invalid Entry"
  121.             txtBox.Text = ""
  122.         End If
  123.     End If
  124. End Sub
  125. Private Sub txt_qty_Change()
  126.     Call Validate_Entry(txt_qty)
  127. End Sub
  128. Private Sub txt_sym_Change()
  129.     Call Validate_Entry(txt_sym)
  130. End Sub
  131. Private Sub txt_name_Change()
  132.     Call Validate_Entry(txt_name)
  133. End Sub

now to save the text inputted in the textbox in a file....use this
(frm_dir)

VB Code:
  1. Option Explicit
  2. Public profilepath As String
  3. Public finalprofile As String
  4. Private Sub Form_Load()
  5. Dim prof As String
  6.     txt_profilepath.Enabled = False
  7.     file1.Enabled = False
  8.     txt_plprofile.Text = frm_loadfile.var1
  9.     prof = frm_field.GetString(txt_plprofile.Text, "-", "C")
  10.     txt_plprofile.Text = prof + ".plp"
  11.      'txt_plprofile.Text = prof + ".plp"
  12. End Sub
  13. Private Sub cmd_cancel_Click()
  14.     MsgBox "Cancelled"
  15.     Unload Me
  16. End Sub
  17. Private Sub cmd_ok_Click()
  18. Dim prof As String
  19. Select Case Me.Caption
  20.     Case "Save Profile"
  21.     txt_profilepath.Text = file1.Path & "\" & file1.FileName & txt_plprofile.Text
  22.         If isFile(txt_profilepath.Text) Then
  23.             txt_plprofile.Text = frm_loadfile.var1
  24.             prof = frm_field.GetString(txt_plprofile.Text, "-", "C")
  25.                 If MsgBox("File " & txt_profilepath & " exists.  Do you want to overwrite the current profile?{Y/N]", vbQuestion + vbYesNo, App.ProductName + " Prompt") = vbYes Then
  26.                     SaveProfile txt_profilepath.Text, pl1
  27.                     finalprofile = txt_plprofile.Text
  28.                 Else
  29.                     txt_profilepath.Text = file1.Path & file1.FileName & "\" & prof & Format(Now, "mmddyyyyhhmmss") & ".plp"
  30.                     SaveProfile txt_profilepath.Text, pl1
  31.                     finalprofile = txt_plprofile.Text
  32.                 End If
  33.         Else
  34.             MsgBox "Saving " & txt_profilepath & " as new profile."
  35.             SaveProfile txt_profilepath.Text, pl1
  36.             finalprofile = txt_plprofile.Text
  37.         End If
  38.         profilepath = txt_profilepath.Text
  39.         frm_field.cmd_next.Enabled = True
  40.     Case "Load Profile"
  41.         txt_profilepath.Text = file1.Path & "\" & file1.FileName
  42.         MsgBox "Loading " & txt_profilepath & " profile."
  43.             LoadProfile txt_profilepath.Text, pl1
  44.         profilepath = txt_profilepath.Text
  45.         frm_field.cmd_next.Enabled = True
  46. End Select
  47.     Me.Hide
  48. End Sub
  49. Private Sub LoadProfile(WhatFile As String, TheProfile As partslist)
  50. Dim FreeFileHandle  As Integer, a$, B() As String
  51.     FreeFileHandle = FreeFile
  52.     Open WhatFile For Input As FreeFileHandle
  53.     With TheProfile
  54.         Line Input #FreeFileHandle, a ' "[Symbol] " & .symbol
  55.         B = Split(a, " ")
  56.         .symbol = B(1)
  57.         frm_field.txt_sym.Text = .symbolic
  58.        
  59.         Line Input #FreeFileHandle, a ' "[Name] " & .Name
  60.         B = Split(a, " ")
  61.         .name = B(1)
  62.         frm_field.txt_name.Text = .name
  63.        
  64.         Line Input #FreeFileHandle, a '  "[Quantity] " & .quantity
  65.         B = Split(a, " ")
  66.         .quantity = B(1)
  67.         frm_field.txt_qty.Text = .quantity
  68.     End With
  69.     Close FreeFileHandle
  70. End Sub
  71. Private Sub SaveProfile(WhatFile As String, TheProfile As namelist)
  72. Dim FreeFileHandle  As Integer
  73.     FreeFileHandle = FreeFile
  74.     Open WhatFile For Output As FreeFileHandle
  75.     With TheProfile
  76.         Print #FreeFileHandle, "[Name] " & .name
  77.         Print #FreeFileHandle, "[Quantity] " & .quantity
  78.         Print #FreeFileHandle, "[Symbolic] " & .symbol
  79.     End With
  80.     Close FreeFileHandle
  81. End Sub
  82. Private Sub dir1_Change()
  83.     file1.Path = dir1.Path
  84. End Sub
  85. Private Sub drive1_Change()
  86.     dir1.Path = drive1.Drive
  87. End Sub
  88. Private Sub file1_PathChange()
  89.     Me.Caption = "Dialog Box - [" & file1.Path & "]"
  90. End Sub
  91. Private Sub file1_Click()
  92.     txt_plprofile.Text = file1.FileName 'file1 is a file list box
  93. End Sub
  94. Function isFile(ByVal sFileName As String) As Integer
  95.   On Error Resume Next
  96.   Dim lFileLength As Long
  97.   Const ATTR_NORMAL = 0
  98.   isFile = False
  99.   If Dir$(sFileName, ATTR_NORMAL) <> "" Then
  100.   lFileLength = FileLen(sFileName)
  101.   If (lFileLength > 0) Then isFile = True
  102.   End If
  103. End Function


I hope this helps..
__________________
Yoroshiku,
seraphicmortal


______________________________________________________
Thirst for knowledge can never be quenched...Ask for more!!.


Oh! Please..Show your appreciation by clicking if you deem this post helpful.
Rate this Post!
seraphicmortal is offline   Reply With Quote
Old May 26th, 2005, 08:19 PM   #10
seraphicmortal
Member
 
seraphicmortal's Avatar
 
Join Date: May 05
Posts: 56
seraphicmortal is an unknown quantity at this point (<10)
Cool Re: Reading form text file

The codes above btw came not only from me but with the help of our buds from vbforum.. (Baja and Joacim)

You can go here to view my thread...
http://www.vbforums.com/showthread.php?t=339887
__________________
Yoroshiku,
seraphicmortal


______________________________________________________
Thirst for knowledge can never be quenched...Ask for more!!.


Oh! Please..Show your appreciation by clicking if you deem this post helpful.
Rate this Post!
seraphicmortal is offline   Reply With Quote
Old May 26th, 2005, 11:25 PM   #11
rdcody
Addicted Member
 
Join Date: Aug 00
Posts: 152
rdcody is an unknown quantity at this point (<10)
Re: Reading form text file

Thanks for the reply, but I'm still having trouble with the Split function. I'm
going to have to find a different way of doing this.
rdcody is offline   Reply With Quote
Old May 26th, 2005, 11:38 PM   #12
seraphicmortal
Member
 
seraphicmortal's Avatar
 
Join Date: May 05
Posts: 56
seraphicmortal is an unknown quantity at this point (<10)
Question Re: Reading form text file

mind expounding why you're having trouble using Split function?
__________________
Yoroshiku,
seraphicmortal


______________________________________________________
Thirst for knowledge can never be quenched...Ask for more!!.


Oh! Please..Show your appreciation by clicking if you deem this post helpful.
Rate this Post!
seraphicmortal is offline   Reply With Quote
Old May 27th, 2005, 08:07 AM   #13
rdcody
Addicted Member
 
Join Date: Aug 00
Posts: 152
rdcody is an unknown quantity at this point (<10)
Re: Reading form text file

I use VB5, and the Split function that manavo11 supplied just doesn't seem
to work.
rdcody is offline   Reply With Quote
Old May 27th, 2005, 12:49 PM   #14
Aaron Young
Guru
 
Aaron Young's Avatar
 
Join Date: Jun 99
Location: Red Wing, MN, USA
Posts: 2,170
Aaron Young has a spectacular aura about (150+)Aaron Young has a spectacular aura about (150+)
Re: Reading form text file

Try:
VB Code:
  1. Private Function SplitEx(ByVal sString As String, Optional ByVal sDelim As String = " ") As Variant
  2.     Dim sItem As String
  3.     Dim sList() As String
  4.     Dim lChar As Long
  5.     Dim lCount As Long
  6.    
  7.     Do
  8.       ' Reset Split for non-Quoted Values
  9.       lChar = InStr(sString, sDelim)
  10.        
  11.       If lChar > 0 Then
  12.           ' Extract the Item from the String
  13.           sItem = Left(sString, lChar - 1)
  14.           ' Remove Item from the Remaining String
  15.           sString = Mid(sString, lChar + Len(sDelim))
  16.       Else
  17.           ' Remaining String, becomes final Item
  18.           sItem = sString
  19.           sString = ""
  20.       End If
  21.        
  22.       ' If something was extracted, add it to the Array
  23.       If Len(sItem) > 0 Then
  24.           ReDim Preserve sList(lCount)
  25.           sList(lCount) = sItem
  26.           lCount = lCount + 1
  27.       End If
  28.        
  29.     ' Continue until no more delimiters are found.
  30.     Loop While lChar > 0
  31.    
  32.     ' If there were items, return the array
  33.     If lCount > 0 Then
  34.         SplitEx = sList
  35.     Else
  36.         ' Otherwise return an empty array
  37.         SplitEx = Array()
  38.     End If
  39. End Function
  40. Private Sub Command1_Click()
  41.    Dim intFree As Integer
  42.    Dim strReadText As String
  43.    Dim strTextLines() As String
  44.    
  45.    intFree = FreeFile
  46.    Open "C:\SomeFile.txt" For Binary As #intFree
  47.        strReadText = Space$(LOF(intFree))
  48.        Get #intFree, , strReadText
  49.    Close #intFree
  50.    
  51.    ' Create array of text lines from the file...
  52.    strTextLines = SplitEx(strReadText, vbNewLine)
  53.    
  54.    Text1.Text = strTextLines(0) ' First line...
  55.    Text2.Text = strTextLines(1) ' Second line...
  56. End Sub
Regards,

- Aaron.
__________________
Aaron Young
Red Wing Software, Inc.
Aaron Young is offline   Reply With Quote
Old May 27th, 2005, 01:12 PM   #15
rdcody
Addicted Member
 
Join Date: Aug 00
Posts: 152
rdcody is an unknown quantity at this point (<10)
Re: Reading form text file

Hey Aaron,

I'm still getting the same error...

VB Code:
  1. [b]strTextLines =[/b] SplitEx(strReadText, vbNewLine)

Compile error: "Can't assign to array"

I don't know...I'm about to give up.
rdcody is offline   Reply With Quote
Old May 27th, 2005, 02:45 PM   #16
tacoman667
Hyperactive Member
 
Join Date: May 05
Posts: 258
tacoman667 is an unknown quantity at this point (<10)
Re: Reading form text file

I run VB6 at work and had that same problem the other day. The reason you get that array error when using the split function is because split turns the variable into an array using a delimiter to make distinctions between elements. An example is:


dim fso as FileSystemObject
dim myTextStream as TextStream
dim myReadText() as String

set fso = New FileSystemObject

set myTextStream = fso.OpenTextFile("C:\File.txt")

myReadText = Split(myTextStream.ReadLine, "|") 'The "pipe" symbol is the divider of the text
MsgBox (myReadText(0))
MsgBox (myReadText(1))
MsgBox (myReadText(2))



This is just an example. The split function turns the variable into an array. So make sure you dim that variable accordingly.


I hope this helps.
tacoman667 is offline   Reply With Quote
Old May 27th, 2005, 03:03 PM   #17
rdcody
Addicted Member
 
Join Date: Aug 00
Posts: 152
rdcody is an unknown quantity at this point (<10)
Re: Reading form text file

Well...I don't know...this is above my head. Isn't everything declared properly?
rdcody is offline   Reply With Quote
Old May 27th, 2005, 03:19 PM   #18
tacoman667
Hyperactive Member
 
Join Date: May 05
Posts: 258
tacoman667 is an unknown quantity at this point (<10)
Re: Reading form text file

Try defining a delimiter like I did, instead of vbNewLine. It may be that VB 5 doesn't have that command, I think that is a .NET upgrade.
tacoman667 is offline   Reply With Quote
Old May 27th, 2005, 03:32 PM   #19
Aaron Young
Guru
 
Aaron Young's Avatar
 
Join Date: Jun 99
Location: Red Wing, MN, USA
Posts: 2,170
Aaron Young has a spectacular aura about (150+)Aaron Young has a spectacular aura about (150+)
Re: Reading form text file

Try changing "strTextLines" to a Variant data type instead of a String array, i.e.
VB Code:
  1. Private Sub Command1_Click()
  2. Dim intFree As Integer
  3. Dim strReadText As String
  4. 'Dim strTextLines() As String
  5. Dim strTextLines As Variant
  6. intFree = FreeFile
  7. Open "C:\SomeFile.txt" For Binary As #intFree
  8.     strReadText = Space$(LOF(intFree))
  9.     Get #intFree, , strReadText
  10. Close #intFree
  11. ' Create array of text lines from the file...
  12. strTextLines = SplitEx(strReadText, vbNewLine)
  13. Text1.Text = strTextLines(0) ' First line...
  14. Text2.Text = strTextLines(1) ' Second line...
  15. End Sub
Regards,

- Aaron.
__________________
Aaron Young
Red Wing Software, Inc.
Aaron Young is offline   Reply With Quote
Old May 27th, 2005, 03:40 PM   #20
space_monkey
Fanatic Member
 
space_monkey's Avatar
 
Join Date: Apr 05
Location: 神と歩くこと
Posts: 573
space_monkey will become famous soon enough (80+)
Re: Reading form text file

I'm kinda new and don't really know too much but If you want to avoid the split, you can simply open the file a different way.

VB Code:
  1. dim strArray(0 to NUMOFTXTBOXES -1) as string
  2. dim i as long
  3. dim FileHandle%
  4. dim strFileName as string
  5. FileHandle% = FreeFile
  6. i = 0
  7. Open strFileName For Input As #FileHandle%
  8.     Do While Not EOF(FileHandle%)
  9.         Line Input #FileHandle%, strArray(i)
  10.         i = i+1
  11.     Loop
  12. textbox0 = strArray(0)
  13. textbox1 = strArray(1)
  14. ...
  15. textboxN = strArray(N)
  16. Close FileHandle%


HTH
__________________
Using VB6 or VB.net 2008 with .net 3.5
"Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

Last edited by space_monkey; May 27th, 2005 at 03:47 PM. Reason: Cause I'm a little slow late in the afternoon especially on a friday
space_monkey is offline   Reply With Quote
Old May 27th, 2005, 04:56 PM   #21
rdcody
Addicted Member
 
Join Date: Aug 00
Posts: 152
rdcody is an unknown quantity at this point (<10)
Re: Reading form text file

OK...here are the results...

To tacoman667...I tried that, and it didn't make any difference.

To Aaron...That worked...except if you enter a blank line in the file, then I
get a "subscript out of range" error. In other words, there are 6 lines of
text (2 blank), and when it puts them into the 6 textboxes, it uses the first
four, and then I get the error.

To space_monkey...it worked perfectly!

I want to thank all you guys for helping to figure this out,
Ron
rdcody is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 07:56 PM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.