473,545 Members | 1,310 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Input text from an INI file

8,435 Recognized Expert Expert
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 "ToDirector y", TEXT3 for my "PreText", and TEXT4 for my "ToDirector y".

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\settin gs.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 3905
mortinrido
4 New Member
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 Recognized Expert Expert
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
2481
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 code snipit** Dim strCustFullName as string Dim strCustAddr1 as string
3
12904
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 type=submit value='Done'> </form>
4
1962
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 memo still cuts it short. TransferText cut it short too. Someone suggested that I use the following code. It works, but it populates only one row of...
1
1833
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 know how to read a text file and i can even display the contents o the input file on the prompt. However i am trying to figure out how t save the...
7
2646
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 if I use the web test interface. It also works fine if I call it from an ASP.NET page that has a text box where the XML is pasted and then passed on....
15
4719
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 button will verify the information that has been entered and updates the data base if the data is correct. Update will throw an exception if the data is...
5
8604
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". Same file path containing special characters works fine in one machine, but doesn't work in other. I am using following API function to get short...
8
2679
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 contact_us.php page.Now i can get all the inputs at the other end else the input(type/file) i donot want a submit button what i want that some how io...
1
3283
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 code we have used: CODE: <input type="file" style=" width:100%" id="importFile" name="importFile"/> As per our analysis we got...
0
7457
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7391
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7651
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
5320
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3438
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1869
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1010
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
693
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.