473,405 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to save data in a file?

Hello
For my project, I made a program that computes for FG (Final Grade) of a student, and lists the students who receive awards.

How do I save these data? (the values of the variable FG and the contents of the listboxes) I'm thinking of having a save button, and I really need the code for it, but I can't find a working one anywhere. Also, is it better to save as a text file or as a database? (I'm a moderate beginner, so I don't know what a database is like.)

By the way, I use Visual Basic Express Edition 2008.
If it helps, the listbox names are listVAExcel, listVALead, listCAExcel, and listCALead.

Thank you very much and I hope for your prompt replies! :D
Mar 7 '11 #1
1 1651
Guido Geurs
767 Expert 512MB
This is an example in VB6 how to save data of your 4 lists in the application directory in a file:(demo see attachment)

Expand|Select|Wrap|Line Numbers
  1. Private Sub ComSave_Click()
  2. Dim FNumSave As Integer
  3. Dim LISTidx As Integer
  4.    FNumSave = FreeFile()
  5.    On Error GoTo Error_Saving
  6.    Open App.Path & "\settings.ini" For Output As #FNumSave
  7.       Write #FNumSave, "[ listVAExcel ]"
  8.       With listVAExcel
  9.          For LISTidx = 0 To .ListCount - 1
  10.             Write #FNumSave, .List(LISTidx)
  11.          Next
  12.       End With
  13.       Write #FNumSave, "[ listVALead ]"
  14.       With listVALead
  15.          For LISTidx = 0 To .ListCount - 1
  16.             Write #FNumSave, .List(LISTidx)
  17.          Next
  18.       End With
  19.       Write #FNumSave, "[ listCAExcel ]"
  20.       With listCAExcel
  21.          For LISTidx = 0 To .ListCount - 1
  22.             Write #FNumSave, .List(LISTidx)
  23.          Next
  24.       End With
  25.       Write #FNumSave, "[ listCALead ]"
  26.       With listCALead
  27.          For LISTidx = 0 To .ListCount - 1
  28.             Write #FNumSave, .List(LISTidx)
  29.          Next
  30.       End With
  31.       Write #FNumSave, "[ EOF ]"
  32.    Close #FNumSave
  33. Exit Sub
  34. Error_Saving:
  35.    MsgBox "error saving file"
  36.    Close #FNumSave
  37. End Sub
  38. ___________________________________
  39.  
  40. Private Sub ComLoad_Click()
  41. Dim FNumLoad As Integer
  42. Dim LISTidx As Integer
  43. Dim INPUTDATA As String
  44.    FNumLoad = FreeFile()
  45.    On Error GoTo Error_Loading
  46.    Open App.Path & "\settings.ini" For Input As #FNumLoad
  47.       Input #FNumLoad, INPUTDATA '§ first line
  48.       Do Until INPUTDATA = "[ EOF ]"
  49.          Select Case INPUTDATA
  50.          Case "[ listVAExcel ]"
  51.             Input #FNumLoad, INPUTDATA '§ first data
  52.             Do Until Left(INPUTDATA, 2) = "[ " '§ until next header
  53.                listVAExcel.AddItem INPUTDATA
  54.                Input #FNumLoad, INPUTDATA
  55.             Loop
  56.          Case "[ listVALead ]"
  57.             Input #FNumLoad, INPUTDATA
  58.             Do Until Left(INPUTDATA, 2) = "[ "
  59.                listVALead.AddItem INPUTDATA
  60.                Input #FNumLoad, INPUTDATA
  61.             Loop
  62.          Case "[ listCAExcel ]"
  63.             Input #FNumLoad, INPUTDATA
  64.             Do Until Left(INPUTDATA, 2) = "[ "
  65.                listCAExcel.AddItem INPUTDATA
  66.                Input #FNumLoad, INPUTDATA
  67.             Loop
  68.          Case "[ listCALead ]"
  69.             Input #FNumLoad, INPUTDATA
  70.             Do Until Left(INPUTDATA, 2) = "[ "
  71.                listCALead.AddItem INPUTDATA
  72.                Input #FNumLoad, INPUTDATA
  73.             Loop
  74.          End Select
  75.       Loop
  76.    Close #FNumLoad
  77. Exit Sub
  78. Error_Loading:
  79.    MsgBox "error loading file"
  80.    Close #FNumLoad
  81. End Sub
Attached Files
File Type: zip How to save data in a file_v1.0.0.zip (2.3 KB, 74 views)
Mar 8 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: I Decker | last post by:
Hi all, Hope this is the right group. I am writing a program in c# to open create an excel document, enter some data, save it and then email it as an attachment. I have successfully created...
0
by: a | last post by:
Save text file as html kloepper 17:42 23 Jul '04 I'm using httpwebresponse and a StringBuilder to return a stream that originates as a file with the .txt suffix (My download code converts the html...
4
by: Mr Gordonz | last post by:
Hi All, I want to be able to save a file from the client's PC on the server. The tricky part is the aspx page is never actually seen by the user. Basically, I have a VB application running on...
5
by: Patrick | last post by:
Following on from the excellent example at http://www.c-sharpcorner.com/Code/2003/Sept/ExportASPNetDataGridToExcel.asp on how to save a data-grid to excel file, how can I extend the example such...
3
by: needin4mation | last post by:
I have data I am reading from a database. I want to take that data, parse it, and put it in between html tags. When I have that row completed in between all the tags, then I want to save that...
4
by: Matt | last post by:
Hi, I would like to save a file locally (on the client computer) in an ASP.net application. It is like the server would return some data that the user can save to a file on his local PC. The ASP...
3
by: Darius | last post by:
Hello, there is an NMEAParserDemo application written in VC++ avaliable for download from http://www.visualgps.net/Papers/NMEAParser/NMEAParserDemo%20Project.zip. Source code in VC++ is...
2
by: phpnoob | last post by:
I have a php script that processes a form and then posts the user input to a data file on the server in a comma delimited format. For simplicity call the file "data.csv." The script is working...
3
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have a question for you. I have a .csv file which has many lines of data. Each line has many data fields which are delimited by ",". Now I need to extract part of data from this...
1
by: dougancil | last post by:
I have the following code: Imports System.IO Imports System.Data Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.