Visual Basic help please

Associate
Joined
11 Nov 2006
Posts
549
Location
Devon
Im creating an application for an assignment and having some troubles and its getting me stressed cause i know its simple.

This is the problem:

On form1 there is a text box where the user enters their name, this text box is called txtNameenter. Then on form3 there is a label this is called lblNamedisplay. Basically i want the name that is entered on form1 to be displayed in the label on form3. This can either be on the press of a command button or it can just be displayed when form3 is displayed.

I have tried the following

Without the command button, code entered into lblNamedisplay:

Private Sub lblNamedisplay_Click()
lblNamedisplay.Caption = Form1.txtNameenter.Text
End Sub

Trying with command button:

Private Sub cmdGenerate_Click()
lblNamedisplay.Caption = Form1.txtNameenter.Text
End Sub

Neither work, can someone please help me out cheers!!!
 
oh my god im so stupid lol

I was putting that code on form3 under the label where i wanted the name entered to be displayed. Where as you put it where the name was entered. I just changed mine and it now works!!!

Thanks I LOVE YOU!!!

EDIT: i will be coming back shortly because:

i need to know how to calculate an average from different figures entered and for it to happen once a command button is displayed.

I also need a total to be calculated on figures once a command button is entered.

i also want the words PASS, FAIL, MERIT, DISTINCTION to be displayed and set to display and defined by a certain number. They should be displayed depending on the total calculated on the figures entered. Again this needs to happen on the press of a command button.

And if possible i want all this to happen when 1 command button is pressed i dont want a seperate command button for each bit if possible?
 
Last edited:
Ok im now at, what i believe to be, the hard part.

Please see images and explanation below:

form2.jpg


Ok on the picture above a student is to enter their marks into the text boxes on the right. I will then want to use these figures entered for some calculations on form3 (below).

form3.jpg


On this form i want the marks entered on the previous form to be calculated and then display : Total Marks and in the box below Average Mark, then in the box below will be grade. In the grade box i want to display Fail, Pass, Merit or Distinction, this will depend on the total mark they have got.

I want the grades defined as

less than 39 = fail
equal to or more than 40 but less than 55 = pass
equal to or more than 56 but less than 70 = merit
more than 70 = distinction

I want these words to be displayed i the grade box after the calculation has been made.

I want all the above things to happen once the generate button has been pressed, is it possible to do this? Basically so that total, average and grade will all be calculated and displayed at once?

Thanks peeps
 
Matt,

Thanks again for the code! You say to change the name of the text box on form2, because you have written the code using a control array!

I really have about 3 weeks knowledge of VB (by 3 weeks i mean 3x3hour lessons ;) ). Could you please explain this a little to me in simple terms and possibly recommend what i should rename the textbox/s to?

I also await flaming from other members for my previous posts lol
 
Hi Matt,

I'm having problems still with my work and wondered if you might be able to help me out again. I did what you said above but im getting an error meesage when pressing the generate button. The error message reads:

Compile Error Invalid inside procedure

IF you have 5 mins could you post back or perhaps add me on msn:

[email protected]

Cheers
 
yeah i get what your saying furnace but i think i've tried everything and have been working on it for 2 days now trying to crack it without asking but i've hit a wall!
 
ok i think im one step closer to getting this to work, i have changed a few things and now im getting the error message:

variable not defined

and its higlighting the x
 
hi furnace

thanks for your post, your right i have used Option Explicit but im unsure ive used it in the right place?

As in my posts above im trying to get 3 calculations to happen on the press of the generate button, so i have coded (as mattyb wrote out for me):

Option Explicit
Dim Total As Integer
Dim Avg As Integer

and then

For x = 0 To Form2.Text1.Count - 1
Total = Form2.Text1(x) + Total
Next x
txt_total = Total

Its the first x in the above code that is being highlighted in when the variable not defined error message appears.
 
furnace are you my programming tutor?????

I know your trying to push me along and i understand that i need to create a variable for x to define it. The problem is i really dont know how, and google is not being my friend at the moment.
 
i wasn't being arsey with you about you being my programming tutor mate i was saying it because she uses the same method as you. Just little hints to try and get you there but without giving you the whole answer.

Am i right in thinking

Dim x As Integer
 
Last edited:
it wasn't meant sarcasticaly at all. Just having a joke, and i do care about learning it. But i'm trying things i havent done before and that i havent been taught so it's new to me. I'm not asking anyone to do it for me and i've asked for help on something im stuck on not the whole assignment.
 
its fine i understand where your coming from its just irritating me that i cant get it to work. I seem to find and fix one error and then another one appears, but i guess thats what programming is all about. But some of this is very new to me so im trying to learn it and understand but at the same time not get to ahead of myself or whats being taught in class.

I seem to have fixed the variable not defined error and my new error is :

Argument not optional

and it highlights txt_total = total

I think it would be handy for tutors to teach you error messages aswell and explain them.
 
yeah i have done that but im still getting the error message Argument not optional and its highlighting the txt_total = Total part at the top of the code?
 
Last edited:
Yeah darrens on my course too, and his statement about our tutor is not an understatement. I have called her over today (im sitting in lesson now) and asked to run through my code with me, her reply was:

Look at the handouts i gave you!!

My tutor teaches by printing something out and giving it to us. She is not even supposed to be a programming tutor as her specialist area is Databases as she was a systems analyst. Now i have no problems with databases, computer systems etc etc but i do have a problem with my programming, as you guys can clearly see.
 
Just want to say thanks for all the help, input and constructive criticsm from all of you. I do finally have the program calculating and working correctly!!

Furnace that explanation was very good and just what i needed.

Shadez, yes my tutor should sit down with us and explain, i think the fact that more than 3 people have posted on here, from my class, asking for help just shows how well our tutor is doing her job. I wasn't asking her for the code today or to do the assignment for me but to simply have a look and explain where im going wrong and what i need to do to correct it. Anyone can work from a sheet that gives you step by step instructions to make somehting happen.

i do have 1 final question about something ( i have checked all my handouts and its not on there :D ) . I have now added another command button to my application. The command button is to enter a new students details, so basically all i want it to do is clear any information entered so that the form can be reused for a new student .

Again, thanks for all your help!! Its appreciated!
 
ok i think i got it, not sure if there is a quicker way but it works :D


to clear the text boxes on screen i have done:

Private Sub cmdnew_Click()
txtname.Text = " "
txtsurname.Text = " "
txtclass.Text = " "
txthistory.Text = " "
txtmaths.Text = " "
txtenglish.Text = " "
txtscience.Text = " "
txtgrade.Text = " "
txttotal.Text = " "
End Sub

I believe i can now move on to my output screen, so dont go too far away from your pc's people ;)
 
ok what the hell, im so grateful of your help im going to ask for more. Now this is something i have never done before (really i mean i have NEVER done thid) But i want to add a little something extra.

On my output page im going to display the results entered such as total marks, grade result and then im going to display a comment such as "well done good marks!" if its a distinction. But i would also like to display a picture depending on the grade results. So if a distinction then i would like a thumbs up pictures be displayed or if fail a thumbs down picture.

Is this going to be hard?
 
Back
Top Bottom