borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (deleting registry keys)Next Topic (POSTING RULES AND GUIDELINES) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Data files within VB6 Solved Topic
Poster Message
Racer-X
Level: Big Cheese


Registered: 20-09-2005
Posts: 26

icon Data files within VB6

I have revamped an old QuickBasic program that used the DATA statement to hold the data in my program.  Now I am putting this program into VB6 and the DATA statement is no longer a valid statement.

Is there an easy way to hold data within a program or is it easier to just load the data from an external file?

30-09-2005 at 03:13 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1616
icon Re: Data files within VB6

Depending on how much information there is....

You could store it in an array, or external file (database, text file, etc)



____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

30-09-2005 at 06:45 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
Racer-X
Level: Big Cheese


Registered: 20-09-2005
Posts: 26
icon Re: Data files within VB6

I end up putting the data into an array, but how do I hold the data before it is in the array?  I used to use the DATA statement along with the READ statement to load up the array.

I think there is too much data to enter into a listbox (albeit invisable)

30-09-2005 at 10:15 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: Data files within VB6

Hi,
Hope the following code will help. Paste it into a module and call the functions to read/save the array from/to file.


Usage:
dim ar(10) as integer
dim i as integer

for i=1 to 10
  ar(i) = 19 + i
next i

SaveArrayToFile ar, "c:\mydata.txt"

dim new_ar() as integer
new_ar = ReadArrayFromFile ("c:\mydata.txt")



public sub SaveArrayToFile (arArray() as integer, strFileName as string)
  dim fout as integer

  ' Get a free number for the file
  fout = freefile

  ' Open the file for writing to
  open strFileName for output as fout

  dim i as integer

  ' as we are going to be reading the file in later, we output the size as the first line
  print #fout, ubound(arArray)

  ' loop through the array, printing out the values
  for i=lbound(arArray) to ubound(arArray)
    print #fout,ararray(i)
  next i

  ' close the file
  close fout
end sub

public sub ReadArrayFromFile (strfileName as string) as integer()
  dim fin as integer
  dim arArray() as integer
  dim strAline as string
  dim i as integer
  dim arraysize as integer
  fin=freefile

  open strfilename for input as fin

  ' the first line is the size of the array
  ' read a line
  line input #fin,strAline
  ' set up the array
  arraysize = val(strAline)
  redim (ararray(arraysize))

  ' read the items from the file
  for i=1 to arraysize
    line input #fin, strAline
    arArray(i) = val(strAline)
  next i

  ' close the file
  close fin
end sub


Hope this helps,
Kieron


____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

01-10-2005 at 07:08 PM
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1616
icon Re: Data files within VB6

if the data's not stored in a file, you have to manually set the values like you would any other variable (only taking into account the array element)

____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

01-10-2005 at 10:43 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
Racer-X
Level: Big Cheese


Registered: 20-09-2005
Posts: 26
icon Re: Data files within VB6

Thanks,  You guys are awesome!  This gives me ideas on the best way to proceed.

02-10-2005 at 06:42 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : VB General : Data files within VB6 Solved Topic
Previous Topic (deleting registry keys)Next Topic (POSTING RULES AND GUIDELINES) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder