The Jedi Academy. THE Place for Jedi training.
Forums
Content
The Academy
Learn
Communicate
Personal


Forums | General Discussion
Visual Basic 6.0
Jun 22 2004 08:27pm

Bail Hope of Belouve
 - Student
Bail Hope of Belouve
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 (:P), because we all know Microsoft pretty much sucks:P
But I had to learn VB for school, so I'm using what I've learned:P

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
Jul 26 2004 01:07pm

Bail Hope of Belouve
 - Student
 Bail Hope of Belouve

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.


Jul 25 2004 10:16pm

n00b
 - Student
 n00b

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...

Jul 23 2004 05:04pm

Bail Hope of Belouve
 - Student
 Bail Hope of Belouve

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.

Jun 25 2004 02:12am

n00b
 - Student
 n00b

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?:P:eek:


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.

Jun 24 2004 09:40pm

tarpman
 - The Tarped Avenger
 tarpman

I'll just stick to my C++ and ASM :D no machine code for me yet! :P
_______________
Saving the world, one kilobyte at a time.

Jun 24 2004 05:58pm

Bail Hope of Belouve
 - Student
 Bail Hope of Belouve

I'll just stick to my Visual Basic :P
_______________
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.


Jun 24 2004 05:32pm

_cmad_
 - Ex-Student
 _cmad_

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.

Jun 24 2004 02:27pm

Bail Hope of Belouve
 - Student
 Bail Hope of Belouve

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.


Jun 24 2004 01:55pm

_cmad_
 - Ex-Student
 _cmad_

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 :o
_______________
Your friends of today, are your enemies of tomorrow.

Jun 24 2004 12:56pm

Bail Hope of Belouve
 - Student
 Bail Hope of Belouve

it's actually built up pretty logical...
that's why I'm almost the only one in my class who gets the language right :D:P
_______________
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.

Jun 24 2004 12:51pm

_cmad_
 - Ex-Student
 _cmad_

oh god VB is weird :P
_______________
Your friends of today, are your enemies of tomorrow.

Jun 24 2004 12:41pm

Bail Hope of Belouve
 - Student
 Bail Hope of Belouve

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?:P:eek:
_______________
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.


Jun 24 2004 12:36pm

_cmad_
 - Ex-Student
 _cmad_

First of all, you didn't post any code :P

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.

Jun 24 2004 12:19pm

Bail Hope of Belouve
 - Student
 Bail Hope of Belouve

yes, cmad rules :P

Now back to topic...

Never mind, already found it :D
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 :P
_______________
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.

Jun 24 2004 07:46am

_cmad_
 - Ex-Student
 _cmad_

damn straight :P :D
_______________
Your friends of today, are your enemies of tomorrow.

Jun 24 2004 01:58am

tarpman
 - The Tarped Avenger
 tarpman

yes, cmad, I'm sure you write machine code on a regular basis. I guess I'm just not as 1337 as you yet. :P
_______________
Saving the world, one kilobyte at a time.

Jun 24 2004 12:09am

JamesF1
 - Student
 JamesF1

:D
_______________
Website

Jun 23 2004 10:42pm

_cmad_
 - Ex-Student
 _cmad_

Quote:
/me sabers everyone, burns this thread, and sets up an "ASM RULES!!" thread. :D


ASM is for sissies. I write machine code :P (© Fizz & © DJ_Sith (either of the two violated the copyright :P))
_______________
Your friends of today, are your enemies of tomorrow.

Jun 23 2004 10:28pm

JamesF1
 - Student
 JamesF1

To put it simply, do a 'While not EOF' loop until it has read all the lines :)
_______________
Website

Jun 23 2004 09:40pm

tarpman
 - The Tarped Avenger
 tarpman

/me sabers everyone, burns this thread, and sets up an "ASM RULES!!" thread. :D
_______________
Saving the world, one kilobyte at a time.

Jun 23 2004 05:10am

n00b
 - Student
 n00b

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.

Jun 22 2004 11:02pm

_cmad_
 - Ex-Student
 _cmad_

Oi oi I read some of the google tutorials from Aron's link, and boy VB is weird :P It's way too... human readable :P Gotta love C and C++ :D
_______________
Your friends of today, are your enemies of tomorrow.

Jun 22 2004 10:45pm

Khâ D'Kana
 - Student
 Khâ D'Kana

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


Jun 22 2004 09:45pm

Bail Hope of Belouve
 - Student
 Bail Hope of Belouve

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.


Jun 22 2004 09:22pm

Aron
 - Retired
 Aron

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!