473,405 Members | 2,187 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.

Input text from an INI file

8,435 Expert 8TB
Please help me.

I am a really ... really... new comer to this VB. I never got any tiny experience using this program.

Now, i'm going to break my rule and start learning VB which is i think it's very useful.

Well, I have an ".ini" file that contains my setting configuration. Below is the example of my ".ini" file :


#Please do not delete this file
#file type : testing program only
#Application name : testing program
#Created by : myself, just try to understand
#created date : July 25, 2007
#Modified date : July 25, 2007
#
[PreText]
"^S "
[PostText]
"N- "
[FromDirectory]
E:\Test
[ToDirectory]
E:\Test\Update




Then, I try to make a FORM (standard .EXE), which contains TEXT1 for my Indication of "FromDirectory", TEXT2 for my "ToDirectory", TEXT3 for my "PreText", and TEXT4 for my "ToDirectory".

So, when I try to compile the program, first it will appear to user the current configuration of ".ini" file for designated TEXT box.

Here's my "premature" program, which I can not get the selected row for my program.


Dim pretext As String
Dim posttext As String
Dim fromdirectory As String
Dim todirectory As String
Open "E:\Test\settings.ini" For Input As #1

Input #1, a$, b$, c$, d$
pretext = a
posttext = b
fromdirectory = c
todirectory = d

Text1.Text = fromdirectory
Text2.Text = todirectory
Text3.Text = pretext
Text4.Text = posttext
Close #1

End Sub




But, by above program, I only available to read the first line. When I tried to change to #2, or #10, or #14, still the program ONLY read my first line... ughhh..

Please help me with this.

I'm currently using Visual Basic 6 (not visual studio 2005).

Thank you.
The Input #1 statement simply reads in one line from a text file (in this case you INI file) and places the values from it into one or more variables. So what you are reading in this statement is "#Please do not delete this file". My guess is that would all be placed in the first variable, a$.

The information held in your file is much more complex than can be handled by a single Input # statement. Probably your best bet is to keep looping and grabbing lines until you find the one you want. Here's a sample routine...
Expand|Select|Wrap|Line Numbers
  1.   Dim pretext As String
  2.   Dim posttext As String
  3.   Dim fromdirectory As String
  4.   Dim todirectory As String
  5.   Dim a As String
  6.   Open "E:\Test\settings.ini" For Input As #1
  7.  
  8.   Do Until EOF(1)
  9.  
  10.     Input #1, a
  11.     Select Case a
  12.       Case "[PreText]"
  13.         Input #1, pretext
  14.       Case "[PostText]"
  15.         Input #1, posttext
  16.       Case "[FromDirectory]"
  17.         Input #1, fromdirectory
  18.       Case "[ToDirectory]"
  19.         Input #1, todirectory
  20.     End Select
  21.   Loop
  22.   Close #1
  23.  
  24.   Text1.Text = fromdirectory
  25.   Text2.Text = todirectory
  26.   Text3.Text = pretext
  27.   Text4.Text = posttext
A couple of tips...
  • Keep your variable references consistent. If you are going to use the name a$, then stick to that name, don't call it a somewhere else. You'll just confuse yourself, later.
  • Go to Tool | Options[/b], Editor tab, and turn on Require Variable Declaration. Trust me, you will save yourself a lot of headaches further down the track.
  • In the above code, depending on the contents of the file, you might need to change Input # to Line Input # to grab the entire line. The Input # statement will break off when it hits a comma or various other delimiters, I think.
Jul 26 '07 #1
2 3882
WOW..

I tried, and it works !

Well, i don't know how to thank you for this matter. You make my spirit on again..

I also have turned the "require variable declaration", and I want to follow your suggestion as well.

Hm, think i'd like to modify some areas then. It's from how to open the ".ini" file from random directory (as user dialog box), and after that save the modified ".ini" file if user changed it from the interactive menu i've made.


Regards,
Jul 26 '07 #2
Killer42
8,435 Expert 8TB
I'm glad to hear it worked out. :)

Couldn't quite tell, though, whether you were asking for further help, or just "thinking out loud". If the former, could you try to describe in more detail what the issue is?
Jul 27 '07 #3

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

Similar topics

5
by: Gregg | last post by:
Hello all, I have been banging my head over a problem that I am having reading a comma seperated file (CSV) that can contain from 1 to 10,000 records. My code snipit is as follows: **Start...
3
by: Ben | last post by:
Here's my form: <form name="aForm" method='post'> <input type=file name=file1 onkeypress='KeyPress()'><br> <a id='attachMoreLink' href='javascript:AddFileInput()">Attach More Files </a> <input...
4
by: R Bolling | last post by:
I have a text file from a text document that has very long rows (two or three paragraphs from a text document for each row). Importing to text cuts it off at 255 characters, and importing to a...
1
by: Aalok | last post by:
This is what i want to do. Read a text file as an input and based on that file, Create an outpu text file which saves the contents of the input file in a specifi format in the output file. I...
7
by: Drew Berkemeyer | last post by:
I've encounted a pretty strange problem and I'm not quite sure what to make of it. I have a web service that consumes an XML file as well as a few other parameters. This web service works fine...
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
5
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file"....
8
omerbutt
by: omerbutt | last post by:
hi there i have a form with multiple input (type/text ) fields and three inputs(type/file) fields i have to submit the form via ajax because i have multiple forms on this page ,you can say it is a...
1
by: sandeep kumar shah | last post by:
Hi, We have used a file uploading HTML tag in an HTML page. We need to customize the text displayed on the Button (which is by default “Browse…” for internet explorer). Below is the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.