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
  2.  
  3. ‘I went ahead and defined my variables
  4.     Dim dblSandwichCost As Double
  5.     Dim dblSoupCost As Double
  6.  
  7.  
  8. 'Click TomatoBasil
  9.     Private Sub btnTomatoBasil_Click(sender As Object, e As EventArgs) Handles btnTomatoBasil.Click
  10.  
  11. ‘I mean for this to set SoupCost to the value 2.49        
  12. dblSoupCost = 2.49
  13.  
  14.      End Sub
  15.  
  16.  
  17. 'Click ClassicTurkeyBreast
  18.     Private Sub btnClassicTurkeyBreast_Click(sender As Object, e As EventArgs) Handles btnClassicTurkeyBreast.Click
  19.  
  20. ‘I mean for this to set SandwichCost to the value 3.49
  21.  
  22.         dblSandwichCost = 3.49
  23.  
  24.     End Sub
  25.  
  26.  
  27.  
  28. Private Sub lblCalcSubtotal_Click(sender As Object, e As EventArgs) Handles lblCalcSubtotal.Click
  29.  
  30.       ‘I made dblValue for easy formatting of the final label
  31.  
  32.         Dim dblValue As Double
  33.  
  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)
  35.  
  36.         dblValue = dblSoupCost + dblSandwichCost
  37.  
  38.  ‘And then convert Value to a currency-formatted string
  39.  
  40.         lblCalcSubtotal.Text = dblValue.ToString("C")
  41.  
  42.     End Sub
  43.  
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)
http://www.filehosting.org/file/deta.../Violet469.rar
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).
http://www.dreamincode.net/forums/to...&#entry2124851
Do
try out those and tell me whether they work in your Computer.I have windows 8.1.
Venkatraman
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)

http://www.filehosting.org/file/details/478305/Project469.rar[/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\microsoft.net\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
Violet2

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.