Welcome to Dream.In.Code
Become a VB Expert!

Join 137,373 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,951 people online right now. Registration is fast and FREE... Join Now!




code question

 
Reply to this topicStart new topic

code question

smcmanus
10 Oct, 2008 - 10:28 AM
Post #1

New D.I.C Head
*

Joined: 9 Oct, 2008
Posts: 11

why will "Input #1, strInput" not fill up my array?
CODE

Sub test()

Dim strArray(5) As String
Dim strInput As String

strInput = "strArray(0), strArray(1), strArray(2), strArray(3), strArray(4), strArray(5)"

Open "c:\test.txt" For Input As #1

Do While Not EOF(1)

    Input #1, strInput

Loop

Close #1

End Sub


** Edit ** code.gif
User is offlineProfile CardPM
+Quote Post

tody4me
RE: Code Question
10 Oct, 2008 - 11:08 AM
Post #2

Only Jenny Craig makes thin clients...
Group Icon

Joined: 12 Apr, 2006
Posts: 1,279



Thanked: 3 times
Dream Kudos: 100
My Contributions
Where are you assigning the values to the array? The code that was supplied is not putting anything into the array.

This post has been edited by tody4me: 10 Oct, 2008 - 11:08 AM
User is offlineProfile CardPM
+Quote Post

smcmanus
RE: Code Question
10 Oct, 2008 - 12:00 PM
Post #3

New D.I.C Head
*

Joined: 9 Oct, 2008
Posts: 11

QUOTE(smcmanus @ 10 Oct, 2008 - 11:28 AM) *

why will "Input #1, strInput" not fill up my array?

CODE

Sub test()

Dim strArray(5) As String
Dim strInput As String

strInput = "strArray(0), strArray(1), strArray(2), strArray(3), strArray(4), strArray(5)"

Open "c:\test.txt" For Input As #1

Do While Not EOF(1)

    Input #1, strInput

Loop

Close #1

End Sub




Basically all I am tring to do is avoiding what you see below. I need the data to be in an array therefore I can't use Line Input #1. There must be a cleaner way using an array! Thanks

CODE

Sub test()

Dim strArray(5) As String
Dim strInput As String

Open "c:\test.txt" For Input As #1

Do While Not EOF(1)

Input #1, strArray(0), strArray(1), strArray(2), strArray(3), strArray(4), strArray(5)

Loop

Close #1

End Sub


** Edit **
User is offlineProfile CardPM
+Quote Post

thava
RE: Code Question
10 Oct, 2008 - 05:49 PM
Post #4

D.I.C Regular
Group Icon

Joined: 17 Apr, 2007
Posts: 456



Thanked: 18 times
Dream Kudos: 50
My Contributions
just add like this

vb


Sub test()

Dim strArray(5) As String
Dim strInput As String

Open "c:\test.txt" For Input As #1

Do While Not EOF(1)

Input #1, strArray(i)
i= i+1
if i>5 then exit do
Loop

Close #1

User is offlineProfile CardPM
+Quote Post

akhileshbc
RE: Code Question
11 Oct, 2008 - 03:37 AM
Post #5

D.I.C Head
Group Icon

Joined: 26 Sep, 2008
Posts: 177



Thanked: 3 times
Dream Kudos: 50
My Contributions
Or use like this:

CODE

Sub test()

Dim strArray(5) As String
Dim strInput As String

Open "c:\test.txt" For Input As #1

Input #1, strArray(0)
Input #1, strArray(1)
Input #1, strArray(2)
Input #1, strArray(3)
Input #1, strArray(4)
Input #1, strArray(5)

Close #1

End Sub

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/5/08 01:30AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month