loading the data from a text file into an array?

how do i load the data stored in a text file, into an array in Visual Basic?  I am currently working on a project that will convert english phrases to french.

i am to create a program module....
create suitable storage for the language data
code the form to load the language data into storage immediately as well as create suitable labes and text boxes to allow phrases to be shown.

Can i use global arrays for this?

If so, how?

thanks

eokorie
eokorieAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mikal613Commented:
Option Explicit
'This is on top of your project
Dim Fun(1 To 100, 1 To 100) As String

Private Sub Form_Load()
fun(1,1) = "Hi"
fun(1,2) = "Hi in french"
End Sub
0
Mikal613Commented:
sorry:
dim Free as integer
dim i as integer

free = Freefile

i = 1

Open "C:\French.txt" for input as #Free

Do while not Eof(free)

  fun(i,i) = "Hi"
  fun(i,i + 1) = "Hi in french"

i = i + 1

loop

Close #free

Something like this
0
JacamarCommented:
ok, to store the data, i suggest this format

Hello, bonjour,
How are you, cava,
ect
just make sure that the english and french sayings are separated by a comma.  Then place the text file in the same folder as your application.  Now place the following code in whatever procedure you want it in.

dim Filename as string
dim stTranslate() as string

Filename = app.path + "\French.txt"

Open Filename for Input as #1

Do while not EOF(1)

  inCounter = inCounter + 1
  Redim Preserve stTranslate(1 to inCounter, 1 to 2)
  Input #1, stTranslate(inCounter, 1)
  Input #1, stTranslate(inCounter, 2)

Loop

Close #1




Now,  this will input all your values in to your array.  they will be kept as stTranslate (wordnumber, 1 or 2).  All the ones will be english, and all the twos will be french.  

I hope this is what you are looking for.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

vikram_c90Commented:
There is a very simple way to do this. First of all please answer the following questions:

1)R u going to create the text file urself and create text data in it??
2)Will u save it as a text (.txt) file??

if so, it is very simple.
Create the text file in delimited format eg:
Hello~abcd~Hi~efgh~where~ghyt
Here I have used the Tild "~" sign as a delimiter. All that u need to do is use the Split function in VB. I am giving u the code below:

Dim fileHandle, FP
Dim strData As String
Dim arrData() As String
Set fileHandle = CreateObject("Scripting.filesystemobject")
Set FP = fileHandle.OpenTextFile(<ur text file name>, 1) strData = FP.ReadAll
arrData = Split(strData, "~")
Set fileHandle = Nothing
Set FP = Nothing
Exit Sub

Now the array arrData will contain all the individual words from the text file. All even index valu of the array will contain ur english words and al odd index values will contain your French words. U will need to add a reference to Microsoft Scripting Runtime to ur project. Using this object is much better than using the VB default file handling by the Open method.
I hope this solves ur problem. Please let me know.
0
keenezCommented:
Eokorie,

If you want to store each line as an element of an array, you would most likely have to keep redim'ing a variable .... may I suggest something like this instead

Dim fInt as integer
Dim table as New Collection
fint = freefile
open file for input as #fint

while not eof(fint)
    Line Input #fInt, textLine
    table.add textLine, textLine

wend

You can then scroll through the lines

for i = 1 to table.count

    debug.print table.item(i)
next
0
zfiexpertCommented:
I would dimmension 2 arrays, one for the english version and one for the french version. Then open the file with:

Open "c:\language.txt" for Input As #1

For A = 0 to EOF(1)
Input #1, EnglishArray(A)
Input #1, FrenchArray(A)
Next A

Close #1

This makes using your array for display and input eaisier because the array number will be the same for the English and French strings.

When you create your text file it will look like this:

yes
oui
what
quoi
why
pourquoi

(You have to make this file in notepad or something before you can run the program.)

Simplify.

-Shane
ZFi Enterprises
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zfiexpertCommented:
<CONTINUED>

In that For A loop after the two input statements add this:

Redim Preserve FrenchArray(A)
Redim Preserve EnglishArray(A)

This will add to the array.

-Shane
ZFi Enterprises
0
zfiexpertCommented:
Jeeze, BEFORE THE TWO INPUT STATEMENTS. There.
0
eokorieAuthor Commented:
Thanks to everyone for their input....  but is there way i could do this?

supposing i have two text boxes in visual basic.  in one of them, i will type in an english word and the other textbox displays the french equivalent at the touch of a button...

any ideas?

eokorie
0
JacamarCommented:
load your dictionary of french and english words in to your array when you load the form.  

When you type in the english word.  Have your program find the english word in your array:
  stTranslate (inCounter,1)  - (the one is indicating english)

and have the program output the french word

  stTranslate (inCounter, 2)

To make it faster, You could load up arrays for each letter so that if your english word starts with an "A" then it will only look for that word in the "A" array
0
netwiz562Commented:
This question has been answered.  Please give someone the credit eokorie.

-NetWiz562
0
eokorieAuthor Commented:
This is worked a treat...sorry i took so long to get back
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.