By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,640 Members | 2,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,640 IT Pros & Developers. It's quick & easy.

Using variable in button to give value to label

P: 1
I have tried this on a MacBook with Parallels running Windows 7, and on a Vaio desktop running Windows 7, but both with Visual Studio 2012:

I am trying to use different buttons to assign different values to a variable.
There are 2 variables using different buttons to assign them.
These variables are being added together to assign value to a label.

I believe my error is in my syntax but I have not found out how to use a button to set the value for a variable.

I get no error codes, I just do not get a result in my final label. It stays blank.

Here is a chunk of my code:

Expand|Select|Wrap|Line Numbers
  1. Public Class frmLunchCombos
  3. ‘I went ahead and defined my variables
  4.     Dim dblSandwichCost As Double
  5.     Dim dblSoupCost As Double
  8. 'Click TomatoBasil
  9.     Private Sub btnTomatoBasil_Click(sender As Object, e As EventArgs) Handles btnTomatoBasil.Click
  11. ‘I mean for this to set SoupCost to the value 2.49        
  12. dblSoupCost = 2.49
  14.      End Sub
  17. 'Click ClassicTurkeyBreast
  18.     Private Sub btnClassicTurkeyBreast_Click(sender As Object, e As EventArgs) Handles btnClassicTurkeyBreast.Click
  20. ‘I mean for this to set SandwichCost to the value 3.49
  22.         dblSandwichCost = 3.49
  24.     End Sub
  28. Private Sub lblCalcSubtotal_Click(sender As Object, e As EventArgs) Handles lblCalcSubtotal.Click
  30.       ‘I made dblValue for easy formatting of the final label
  32.         Dim dblValue As Double
  34.  ‘Value= SoupCost (which would be assigned to 2.49 after clicking Tomato Basil) + SandwichCost (which would be assigned to 3.49 after clicking ClassicTurkeyBreast)
  36.         dblValue = dblSoupCost + dblSandwichCost
  38.  ‘And then convert Value to a currency-formatted string
  40.         lblCalcSubtotal.Text = dblValue.ToString("C")
  42.     End Sub
Many thanks in advance! I really want to understand this and I feel like it's something simple.
Mar 19 '15 #1
Share this Question
Share on Google+
2 Replies

P: 4
Dear Friend,
Your problem invoked a hornets nest in my programming world.I was doing C-Pad programming(cmd & notepad)
and suddenly i found your problem has creeped in to my C-Pad also.No textbox,listbox or label is responding
to button click.It was working easily for me all these days.Microsoft uploaded many updates recently(just 3 days since)
They must have screwed up something.Anyway,i did your project in visual studio express 2013 and uploaded to
the URL:-(given below)
I used a listbox instead of label.No problem.Even Label and Textbox will work fine.Now i will have to analyse what went
wrong in my C-Pad style.I have uploaded many projects to the following URL:-(It includes VB.Net and WPF-with-VB.Net).
try out those and tell me whether they work in your Computer.I have windows 8.1.
Mar 21 '15 #2

P: 4
Dear Friend,
I worked further and made your project as per your expectations.I also found out that It is not Microsoft who screwed up,But it is me.
I actually had a simple error which i overlooked.Anyway it helps me to blame Microsoft first and then on retrying locate the blame on myself.
(Not surprising considering my age-68+)This project is named Project469 and uploaded to URL:-(It is in C-Pad style)[/url]

You have to call the compiler from your cmd window as given below.First place the two .vb files(Violet2.vb and Violet22.vb) in a folder
-New folder(you can name it appropriately).
The compiler calling is:-

path=%path%;c:\windows\\framework\v4. 0.30319
VBC /OUT:Violet2 /T:winexe C:\Users\.......\Desktop\Folder\Violet2.vb
VBC /OUT:Violet2 /T:winexe C:\Users\.......\Desktop\Folder\Violet22.vb C:\Users\VEKATRAMAN\Desktop\New folder\Violet2.vb

NOTE:The dotted portion is particular to your computer.Mostly it will be your name.Change the New folder to whatever you want.
This project is exactly what you wanted-with ListBox as a bonus addition.
Mar 21 '15 #3

Post your reply

Sign in to post your reply or Sign up for a free account.