Visual Basic 6.0 | |
Bail Hope of Belouve - Student |
Anyone know it? Or fairly experienced with it? You see, I'm writing a little program, and have stumbled across a problem... Now don't give me that Microsoft s*cks nonsense (), because we all know Microsoft pretty much sucks But I had to learn VB for school, so I'm using what I've learned Anyway, the problem is the following (if you happen to know something about it please help me out) So, a multi-line message is written in a textfile. I want my program to load up the textfile and enter all the data in a textbox. But when I use the code: Open "<file>" for Input as #1 Input #1, Text1 txtMessage.text = Text1 Close #1 It only shows the first line, and nothing else and I can't figure out a way to solve this problem anyone got an idea? You would be helping me out sincerely Thanks in advance! _______________ Visit the Belouve Family Website! Quote: I try to have fun with my friends and try to make a difference as best I can. What does making a difference mean? Well, it can be as simple as saying hello, answering a question that seems obvious or heck, just talking. -- Vladarion
Want to know Vladarion? Read the Article about his life here. This post was edited by Bail Hope of Belouve on Jun 22 2004 08:34pm. |
< Recent Comments | Login and add your comment! |
Comments |
Bail Hope of Belouve - Student |
yes thank you A quick question If I would just compile my program into an .exe and put this file into a zip, would it work on other computers? I've read (and I'm being told) that I should include vb6run.dll, but I can't find this one anywhere... Where should it be? and do I have to include it? (another thing I'm worrying about... would this work on Linux or Mac as well?) _______________ Visit the Belouve Family Website! Quote: I try to have fun with my friends and try to make a difference as best I can. What does making a difference mean? Well, it can be as simple as saying hello, answering a question that seems obvious or heck, just talking. -- Vladarion
Want to know Vladarion? Read the Article about his life here. |
n00b - Student |
The subscript out of range is the result of this: Description(M + 1) = Response1 When M is 1000, M + 1 is 1001, which is probably one higher than the upper bound of the Description array. I'm only guessing that you have a line like this somewhere: Dim Description(1000) As String Make it 1001 and the code won't give you that error or lessen the upper bound of the For loop: For M = 0 to 999 _______________ Gone but hopefully not forgotten... |
Bail Hope of Belouve - Student |
Quote: Dim M As Integer If Response1 = "" Or Response2 = "" Then Exit Sub Else For M = 0 To 1000 If Description(M) = "" And URL(M) = "" Then Description(M) = Response1 URL(M) = Response2 cboLinks.AddItem Response2 cboDescription.AddItem Response1 ElseIf Description(M) Like "*" And Description(M + 1) = "" And URL(M + 1) = "" Then Description(M + 1) = Response1 URL(M + 1) = Response2 cboLinks.AddItem Response2 cboDescription.AddItem Response1 End If Next M Can anyone please say what's wrong with this code? I want it to check which Array of M(variable for a number) is still available. Thus the IF-clause. The error I get is two-fold First, if I have no M's, then it'll repeat M(1) a thousand times, which isn't the idea. It only adds it a thousand times to cboDescription, but does not write it a thousand times to the file, so the mistake is somewhere above. If I do have M's, then it'll give me the following error: Subscript out of range Anyone can help me? _______________ Visit the Belouve Family Website! Quote: I try to have fun with my friends and try to make a difference as best I can. What does making a difference mean? Well, it can be as simple as saying hello, answering a question that seems obvious or heck, just talking. -- Vladarion
Want to know Vladarion? Read the Article about his life here. This comment was edited by Bail Hope of Belouve on Jul 24 2004 01:39pm. |
n00b - Student |
Quote: Open "<file>" For Append As #1 Print #1, txtNewEngagement; " " & txtDate Unload frmAddEngagement Unload frmDiary frmDiary.Show Close #1 That's how it is in VB OMG I thought of that on my own maybe there is a future for me as a Programmer? Take the semi-colon out for the Print line and concatenate it all together: Print #1, txtNewEngagement & " " & txtDate BTW, I'm a professional Visual Basic programmer. If you need assistance, just ask me in my profile. For the benefit of the other people here, #1 is not a "variable name." It is the file handle. VB numbers open files, so he is essentially saying Open the file as file number 1. If he wanted to open another file before closing the first, it would be file number 2. VB doesn't require you to manually number your files. You can ask VB what the next open file number is with the FreeFile function as so: Dim lngFreeFile as Long lngFreeFile = FreeFile Open "myfile.txt" For Input as #lngFreeFile Print #lngFreeFile, "Hello" Close #lngFreeFile I suggest using that method whenever you use the sequential file functions. _______________ Gone but hopefully not forgotten... This comment was edited by n00b on Jun 25 2004 02:16am. |
tarpman - The Tarped Avenger |
I'll just stick to my C++ and ASM no machine code for me yet! _______________ Saving the world, one kilobyte at a time. |
Bail Hope of Belouve - Student |
I'll just stick to my Visual Basic _______________ Visit the Belouve Family Website! Quote: I try to have fun with my friends and try to make a difference as best I can. What does making a difference mean? Well, it can be as simple as saying hello, answering a question that seems obvious or heck, just talking. -- Vladarion
Want to know Vladarion? Read the Article about his life here. |
_cmad_ - Ex-Student |
Quote: procedure TForm1.Button1Click(Sender : TObject) Procedure name & params. Automatically added by Delphi. Quote: var fOut : TextFile; Variable definition Quote: begin Assign(fOut, 'textfile.txt'); Rewrite(fOut); writeln(fOut, Edit1.Text + ' ' + Edit2.Text); Closefile(fOut); end; Main code _______________ Your friends of today, are your enemies of tomorrow. |
Bail Hope of Belouve - Student |
logical? I can't figure head nor tails to that code _______________ Visit the Belouve Family Website! Quote: I try to have fun with my friends and try to make a difference as best I can. What does making a difference mean? Well, it can be as simple as saying hello, answering a question that seems obvious or heck, just talking. -- Vladarion
Want to know Vladarion? Read the Article about his life here. |
_cmad_ - Ex-Student |
THIS code in Delphi is more logical than VB procedure TForm1.Button1Click(Sender : TObject) var fOut : TextFile; begin Assign(fOut, 'textfile.txt'); Rewrite(fOut); writeln(fOut, Edit1.Text + ' ' + Edit2.Text); Closefile(fOut); end; heck i'd never imagine that #1 could be a variable name _______________ Your friends of today, are your enemies of tomorrow. |
Bail Hope of Belouve - Student |
it's actually built up pretty logical... that's why I'm almost the only one in my class who gets the language right _______________ Visit the Belouve Family Website! Quote: I try to have fun with my friends and try to make a difference as best I can. What does making a difference mean? Well, it can be as simple as saying hello, answering a question that seems obvious or heck, just talking. -- Vladarion
Want to know Vladarion? Read the Article about his life here. This comment was edited by Bail Hope of Belouve on Jun 24 2004 01:18pm. |
_cmad_ - Ex-Student |
oh god VB is weird _______________ Your friends of today, are your enemies of tomorrow. |
Bail Hope of Belouve - Student |
Open "<file>" For Append As #1 Print #1, txtNewEngagement; " " & txtDate Unload frmAddEngagement Unload frmDiary frmDiary.Show Close #1 That's how it is in VB OMG I thought of that on my own maybe there is a future for me as a Programmer? _______________ Visit the Belouve Family Website! Quote: I try to have fun with my friends and try to make a difference as best I can. What does making a difference mean? Well, it can be as simple as saying hello, answering a question that seems obvious or heck, just talking. -- Vladarion
Want to know Vladarion? Read the Article about his life here. |
_cmad_ - Ex-Student |
First of all, you didn't post any code Then, here's what i guess would work (it's Delphi code though): writeln(outputfile, Text1.Text + Text2.Text); So you gotta kinda "append" the text of the 2nd text box to the first. My only guess in VB is: MyText = Text1.Text & Text2.Text print #1, MyText dunno how VB handles text boxes' strings, so that's merely a logical guess :\ _______________ Your friends of today, are your enemies of tomorrow. |
Bail Hope of Belouve - Student |
yes, cmad rules Now back to topic... Never mind, already found it I was just wondering the following I want the info in two textboxes printed to a file, and in the file they have to be like this: (fictional data below) Paddy Class 24/06/2004 But when I try the Print Command it prints: Paddy Class 24/06/2004 I've been trying, but somehow it refused to print everything to one line... Anyone have a thought Oh btw The data has to end up in a combobox like this: Paddy class 24/06/2004 I've found out how to put it into the combobox, but it still inputs: Paddy Class 24/06/2004 So that's why I need to know how to get everything on one line... Btw, if there happens to be a script to get something which was printed on two lines on one line, then please help me out _______________ Visit the Belouve Family Website! Quote: I try to have fun with my friends and try to make a difference as best I can. What does making a difference mean? Well, it can be as simple as saying hello, answering a question that seems obvious or heck, just talking. -- Vladarion
Want to know Vladarion? Read the Article about his life here. This comment was edited by Bail Hope of Belouve on Jun 24 2004 12:23pm. |
_cmad_ - Ex-Student |
damn straight _______________ Your friends of today, are your enemies of tomorrow. |
tarpman - The Tarped Avenger |
yes, cmad, I'm sure you write machine code on a regular basis. I guess I'm just not as 1337 as you yet. _______________ Saving the world, one kilobyte at a time. |
JamesF1 - Student |
_______________ Website |
_cmad_ - Ex-Student |
Quote: /me sabers everyone, burns this thread, and sets up an "ASM RULES!!" thread. ASM is for sissies. I write machine code (© Fizz & © DJ_Sith (either of the two violated the copyright )) _______________ Your friends of today, are your enemies of tomorrow. |
JamesF1 - Student |
To put it simply, do a 'While not EOF' loop until it has read all the lines _______________ Website |
tarpman - The Tarped Avenger |
/me sabers everyone, burns this thread, and sets up an "ASM RULES!!" thread. _______________ Saving the world, one kilobyte at a time. |
n00b - Student |
Open "<file>" for Input as #1 Do Input #1, Text1 Text2 = Text2 & Text1 Loop Until EOF(1) Close #1 txtMessage.text = Text2 Thats what it should say. The Input command only inputs a single line of text at a time. _______________ Gone but hopefully not forgotten... This comment was edited by n00b on Jun 23 2004 05:13am. |
_cmad_ - Ex-Student |
Oi oi I read some of the google tutorials from Aron's link, and boy VB is weird It's way too... human readable Gotta love C and C++ _______________ Your friends of today, are your enemies of tomorrow. |
Khâ D'Kana - Student |
Bail you could try to use a RichTextBox inside of the TextBox. If I remember well (I studied VB.NET last year) the TextBox will always stop the text at the first end line character but the RichTextBox allow multi-line. Hope it will work -Khâ D'Kana _______________ In light of day, nor dark of night, no evil shall escape our sight. Proud member of the D'Kana family |
Bail Hope of Belouve - Student |
okay, that certainly solved my problem. Many thanks to you Aron It made my job a lot easier actually! Can't thank you enough! _______________ Visit the Belouve Family Website! Quote: I try to have fun with my friends and try to make a difference as best I can. What does making a difference mean? Well, it can be as simple as saying hello, answering a question that seems obvious or heck, just talking. -- Vladarion
Want to know Vladarion? Read the Article about his life here. |
Aron - Retired |
Alright. I know absolutely ZERO about visual basic. The only client-side windows programming I know is Delphi, and starting to learn C. From what I have heard, Visual Basic pretty much sucks, but since that is not what you ask for, I won't start that discussion This is what I know: Most programming languages have a command like opening files, just like you just showed above. Most of the time it is in the form of: Quote: Open("filename","w/r/w+/r+" something like that. However, opening the file only tells the compiler to OPEN the file, and (sometimes) read out the first line. You will probably have to set a variable to the open command; something like this: Quote: MyVariable = Open("yourfile" Then, you will have to use a while loop to read out the file, one by one. For example, TCL uses GETS (in combination with EOF) for that, as do many other languages. So let's assume VB has something like that: Quote: while (!EOF $MyVariable) { GETS $MyVariable $line do_your_input_into_textbox_stuff_here } Anyway, as I said, I know nothing about VB, but it is almost certain you will have to use some sort of a While-loop, set each line to a variable/put them into a list/array, and dump the entire thing into the input. You might also want to search for reading files with visual basic in google. It is your friend. Good luck |
< Recent Comments | Login and add your comment! |