Reply to topic  [ 12 posts ] 
Visual Basic 2010 question about displaying data in a form 
Author Message
I haven't seen my friends in so long
User avatar

Joined: Fri Apr 24, 2009 7:55 am
Posts: 7935
Location: Manchester.
Reply with quote
Hi,

OK, I'm not exactly sure how to describt this but I'll try anyway...

I'm writing an application using Visual Basic 2010, and I have 2 sets of Radio buttons. I have gotten as far as being able to select a button in each set, and that in turn sets a variable to a value depending on which button is selected. I should point out that I click a button to perform the calculation, which is what I want...

What I need is a way to have those values displayed somewhere on the screen.

I have managed to create a message box with the data displayed, but I want the data on the screen, as I will be re-using the variable for something else...

Here are some code snippets, if it helps...

Code:
Public Shared ndval As Integer
    Public Shared ssval As Double
    Public Shared expotime As Integer
    Public Shared radio1 As Integer
    Public Shared expo1 As Double
    Private Property radiol As Double

This is where I set the variables, (some of which are no longer needed, but I'll remove them later)

Code:
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        If RadioButton1.Checked Then ndval = 1
    End Sub

I have one of these set up for each radio button, and yes I know that there is probably a far easier way, but I'll refine the code after I get the damned thing working!
By the way, I also use the same sort of code to assign a value to ssval

Code:
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        expo1 = ndval * ssval
        MsgBox("The result is... " & expo1)


    End Sub


As I said, I can get the value, (expo1) to appear in a message box, but I want it to appear on the scree... Any ideas, (while I carry on searching)?

Thanks in advance,

John.

:)

_________________
okenobi wrote:
John's hot. No denying it. But he's hardly Karen now, is he ;)

John Vella BSc (Hons), PGCE - Still the official forum prankster and crude remarker :P
Sorry :roll:
I'll behave now.
Promise ;)


Fri Sep 10, 2010 7:45 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 6:36 pm
Posts: 5150
Location: /dev/tty0
Reply with quote
As an incomplete answer:

I think I'd use a label and then do something like:
Code:
expo1 = ndval * ssval;
mylabel.setText(expo1)


Sat Sep 11, 2010 9:18 am
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Fri Apr 24, 2009 7:55 am
Posts: 7935
Location: Manchester.
Reply with quote
forquare1 wrote:
As an incomplete answer:

I think I'd use a label and then do something like:
Code:
expo1 = ndval * ssval;
mylabel.setText(expo1)


Hmmm... interesting... I thought that the second command was Java, or am I losing the plot? Again ;)

OK, I'll give it a go in a little while, once the PC has finished a fairly major encoding job and let you know how I get on.

Thanks.

:D

_________________
okenobi wrote:
John's hot. No denying it. But he's hardly Karen now, is he ;)

John Vella BSc (Hons), PGCE - Still the official forum prankster and crude remarker :P
Sorry :roll:
I'll behave now.
Promise ;)


Sat Sep 11, 2010 10:06 am
Profile WWW
What's a life?
User avatar

Joined: Thu Apr 23, 2009 8:25 pm
Posts: 10691
Location: Bramsche
Reply with quote
That is Java, not VB...

The VB would be:

expo1 = ndval * ssval
mylabel.text = expo1

_________________
"Do you know what this is? Hmm? No, I can see you do not. You have that vacant look in your eyes, which says hold my head to your ear, you will hear the sea!" - Londo Molari

Executive Producer No Agenda Show 246


Sat Sep 11, 2010 3:43 pm
Profile ICQ
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 6:36 pm
Posts: 5150
Location: /dev/tty0
Reply with quote
Aye, I knew Java did it, but I though that VB would be similar, at least similar enough to get you on the right tracks :)


Sat Sep 11, 2010 4:53 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Fri Apr 24, 2009 7:55 am
Posts: 7935
Location: Manchester.
Reply with quote
Thanks guys. Ben, it din indeed put me on the right tracks, and Dave thanks also, for saving me a bit more searching.

It's coming along quite nicely now... :D

_________________
okenobi wrote:
John's hot. No denying it. But he's hardly Karen now, is he ;)

John Vella BSc (Hons), PGCE - Still the official forum prankster and crude remarker :P
Sorry :roll:
I'll behave now.
Promise ;)


Sat Sep 11, 2010 10:01 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Fri Apr 24, 2009 7:55 am
Posts: 7935
Location: Manchester.
Reply with quote
OK, update time... I had to leave this project alone for a while, but I'm finding it's a nice distraction for when I need to stop doing college/uni work for 10 minutes, but I've hit another road block.

I need a way of making a variable available in different forms.

Code:
Public Class Form1
    Public Shared ndval As Double
    Public Shared ssval As Double
    Public Shared expotime As Double
    Public Shared radio1 As Double
    Public Shared expo1 As Double


The variable in question is expo1, and it is dynamically updated with a value, but when I click a button which opens a new form I can't get the value to carry across.

I've tried Googling it, but nothing I've seen has helped... Any bright ideas please?

TIA

:D

_________________
okenobi wrote:
John's hot. No denying it. But he's hardly Karen now, is he ;)

John Vella BSc (Hons), PGCE - Still the official forum prankster and crude remarker :P
Sorry :roll:
I'll behave now.
Promise ;)


Tue Jan 18, 2011 8:35 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 6:58 pm
Posts: 8767
Location: behind the sofa
Reply with quote
If you want a variable to be global across all forms in a project, then you need to add a new module and define it in that. Variables defined in a form can only be used in that form.

Code:
Module Module1
    Public ndval As Double
    Public ssval As Double
    Public expotime As Double
    Public radio1 As Double
    Public expo1 As Double
End Module


I think :lol:

_________________
jonbwfc's law: "In any forum thread someone will, no matter what the subject, mention Firefly."

When you're feeling too silly for x404, youRwired.net


Wed Jan 19, 2011 12:18 am
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Fri Apr 24, 2009 7:55 am
Posts: 7935
Location: Manchester.
Reply with quote
After I added the module and removed the variables from the individual forms it worked a treat, so thanks a million JJ! :D

_________________
okenobi wrote:
John's hot. No denying it. But he's hardly Karen now, is he ;)

John Vella BSc (Hons), PGCE - Still the official forum prankster and crude remarker :P
Sorry :roll:
I'll behave now.
Promise ;)


Wed Jan 19, 2011 9:11 am
Profile WWW
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 4876
Location: Newcastle
Reply with quote
John_Vella wrote:
The variable in question is expo1, and it is dynamically updated with a value, but when I click a button which opens a new form I can't get the value to carry across.

I've tried Googling it, but nothing I've seen has helped... Any bright ideas please?


Easiest way is a global (if vb supports it)

OR

Pass it via the method that opens the form I'd say

_________________
Twitter
Charlie Brooker:
Macs are glorified Fisher-Price activity centres for adults; computers for scaredy cats too nervous to learn how proper computers work; computers for people who earnestly believe in feng shui.


Wed Jan 19, 2011 9:03 pm
Profile
I haven't seen my friends in so long
User avatar

Joined: Fri Apr 24, 2009 7:55 am
Posts: 7935
Location: Manchester.
Reply with quote
Thanks Fin. JJ's method did work, but I'll give the global variables a go as well... always nice to have a few different ways of doing the same thing.

Now all I need to do is find the time to code a countdown timer, (after converting seconds into hours minutes and seconds)

_________________
okenobi wrote:
John's hot. No denying it. But he's hardly Karen now, is he ;)

John Vella BSc (Hons), PGCE - Still the official forum prankster and crude remarker :P
Sorry :roll:
I'll behave now.
Promise ;)


Thu Jan 20, 2011 9:33 am
Profile WWW
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 4876
Location: Newcastle
Reply with quote
John_Vella wrote:
Now all I need to do is find the time to code a countdown timer, (after converting seconds into hours minutes and seconds)


easier to make use of an initial datetime and getting the timespan instead. then you can calculate the difference then convert them (eg seconds = hours * 360)

_________________
Twitter
Charlie Brooker:
Macs are glorified Fisher-Price activity centres for adults; computers for scaredy cats too nervous to learn how proper computers work; computers for people who earnestly believe in feng shui.


Thu Jan 20, 2011 4:30 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 12 posts ] 

Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.