Thanks, I'll try that.
Okay, by putting Exit Sub at bottom it finally closes the window, but here's what is still happening that I don't understand.
When the form loads the For... Next loop works and draws my thermometer going up 18 times, as it should. Then the message box shows. BUT THEN the loop runs again 18 more times, shows the message box again, then closes.
What's up with that?
Thanks
I'm re-posting this because I forgot to put code tags around the code.
I'm trying to make a form with a thermometer painted on it. I want the thermometer to go up
each second. I tried the code below and it sorta works, but not really. It does the For...
Next loop okay and shows the message box, but then does NOT Exit Sub or Me.Close. Instead
it starts the For... Next loop again. When it finishes the For... Next loop the second
time it shows the message box again, then appears to stop executing, but still does
not Me.Close. I guess I don't understand the paint event.
Public Class ThermometerForm
Public intFillTop As Integer = 361
Public intFillHeight As Integer = 28
Private Sub ThermometerForm_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim TimeNow As Date
Dim TimeLater As Date
Dim intWaitTime As Integer = 1 'number of seconds each
TimeNow = DateTime.Now
TimeLater = DateTime.Now
'Draw column of thermometer in blue
e.Graphics.DrawRectangle(Pens.Blue, 410, 40, 10, 350)
'e.Graphics.DrawRectangle(Pens.Blue, 410, 40, 10, 350)
'Draw bulb of thermometer in blue
e.Graphics.DrawEllipse(Pens.Blue, 400, 375, 30, 30)
'Fill bulb of thermometer with red
e.Graphics.FillEllipse(Brushes.Red, 401, 376, 28, 28)
'Dim mp As Integer = intMeltingPoint / 10
'Dim intCurrentTemp As Integer = 0
'Make thermometer go up each second
For t = 1 To 18 'mp '105
TimeNow = DateTime.Now
TimeLater = DateTime.Now
'Put current temp into label
'intCurrentTemp = t * 10
'lblTemp.Text = …
I'm trying to make a form with a thermometer painted on it. I want the thermometer to go up each second. I tried the code below and it sorta works, but not really. It does the For... Next loop okay and shows the message box, but then does NOT Exit Sub or Me.Close. Instead it starts the For... Next loop again. When it finishes the For... Next loop the second time it shows the message box again, then appears to stop executing, but still does not Me.Close. I guess I don't understand the paint event.
Public Class ThermometerForm
Public intFillTop As Integer = 361
Public intFillHeight As Integer = 28
Private Sub ThermometerForm_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim TimeNow As Date
Dim TimeLater As Date
Dim intWaitTime As Integer = 1 'number of seconds each
TimeNow = DateTime.Now
TimeLater = DateTime.Now
'Draw column of thermometer in blue
e.Graphics.DrawRectangle(Pens.Blue, 410, 40, 10, 350)
'e.Graphics.DrawRectangle(Pens.Blue, 410, 40, 10, 350)
'Draw bulb of thermometer in blue
e.Graphics.DrawEllipse(Pens.Blue, 400, 375, 30, 30)
'Fill bulb of thermometer with red
e.Graphics.FillEllipse(Brushes.Red, 401, 376, 28, 28)
'Dim mp As Integer = intMeltingPoint / 10
'Dim intCurrentTemp As Integer = 0
'Make thermometer go up each second
For t = 1 To 18 'mp '105
TimeNow = DateTime.Now
TimeLater = DateTime.Now
'Put current temp into label
'intCurrentTemp = t * …
>I can't do that directly using Visual Studio?
No. In fact, visual studio is not a .net framework. It's an IDE.
If I can't do that with Visual Studio, how come the VS publish wizard lets me select "available online only" then tells me to put in my URL and then tries (unsuccessfully, of course) to access my site?
>How can it be that ClickOnce lets you choose online-only? Does it temporarily install the EXE on the users computer?
Have a look at msdn articles.
1. http://msdn.microsoft.com/en-us/library/wh45kb66.aspx
2. http://msdn.microsoft.com/en-us/library/142dbbz4.aspx
3. http://msdn.microsoft.com/en-us/library/t71a733d.aspx
Thanks, but what about uploading the files to my website... I can't do that directly using Visual Studio?
If I use the Publishing Wizard to try to publish my app to my website, it asks for the URL, but of course, my web host requires a password to access my site, so the wizard can't publish there. How do I publish to my site that requires a password for FTP?
I thought you couldn't run an EXE from a web page, you had to download it. How can it be that ClickOnce lets you choose online-only? Does it temporarily install the EXE on the users computer?
If I want my application to run online only and I use the publishing wizard in Visual Studio, how do I get the whole install thing onto my website? Do I upload something onto my site using FTP?
What do I upload onto the site? And once the files are on my website, what file does the user access to run my application online?
Thanks, that worked!
I'm new at this.
How come this doesn't work...
Private Sub ColorKeyForm_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
'Draws diagonal line of dot and dash on form
Dim objGraphics As Graphics = Me.CreateGraphics
Dim objPen As Pen
objPen = New Pen(Drawing.Color.DarkBlue, 3)
objPen.DashStyle = Drawing2D.DashStyle.DashDot
objGraphics.DrawLine(objPen, 20, 20, 400, 400)
'Next routine does nothing
Dim objPicGraphics As Graphics = picColorKey.CreateGraphics
objPen = New Pen(Drawing.Color.Chartreuse, 5)
objPen.DashStyle = Drawing2D.DashStyle.Dot
objPicGraphics.DrawLine(objPen, 20, 20, 400, 400)
End Sub
... the top part draws a line on the form but the second part does nothing. The picColorKey is a picture box on the form.
Got it. Thanks!
Is there a way to wrap the text on the list box items, i.e. go to the next line, when they're too long for the box. A few of my items are too long to fit, so they are truncated.
I'm a novice at VB.NET and I'm having a problem with the compiled versions of my applications.
If I take the .exe file (it's real small, like 40KB) from the BIN/DEBUG directory, it runs fine on most computers (I've tried it on 5), including Windows 7, Vista and XP. When I take the same file to work and try to run it either from the server (Novell) or directly on a workstation (XP). I get an error message that includes something like "Can't initialize..."
Why is this? Is the .EXE in the DEBUG directory not compiled correctly?
Thanks for that... I'll try getting the code out of the paint event. It never occurred to me that I didn't have to put it in the paint event.
It's part of a lab simulation my chemistry students are going to do. They're heating water from 20 degrees and they're going to chose how hot they want it. I'm getting their input from the main form.
Thanks again...
I'm really a novice and I'm trying to draw a thermometer that moves up or down with temp change. I created a second form on my project for the thermometer and access it using Thermometer.Showdialog(().
Then on the thermometer form, I'm using this code:
Private Sub ThermometerForm_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim g As Graphics = e.Graphics
Dim TimeNow As Date
Dim TimeLater As Date
Dim intWaitTime As Integer = 1
TimeNow = DateTime.Now
TimeLater = DateTime.Now
intWaitTime = 1 'number of seconds each
For t = 1 To 33
TimeNow = DateTime.Now
TimeLater = DateTime.Now
'Draw column of thermometer in blue
g.DrawRectangle(Pens.Blue, 410, 40, 10, 350)
'e.Graphics.DrawRectangle(Pens.Blue, 410, 40, 10, 350)
'Draw bulb of thermometer in blue
g.DrawEllipse(Pens.Blue, 400, 375, 30, 30)
'Fill shapes after outline, so fill covers parts _
'of shapes
'Fill column of thermometer with red
g.FillRectangle(Brushes.Red, 411, intFillTop, 8, intFillHeight)
'e.Graphics.FillRectangle(Brushes.Red, 411, 41, 8, 348)
'Fill bulb of thermometer with red
e.Graphics.FillEllipse(Brushes.Red, 401, 376, 28, 28)
intFillTop = intFillTop - 10
intFillHeight = intFillHeight + 10
'Time Delay
Do
TimeLater = DateTime.Now
Application.DoEvents()
Loop Until DateDiff(DateInterval.Second, TimeNow, TimeLater) >= _
intWaitTime
Next
End Sub
It works great and shows the red moving up though the rectangle. Problem is that when it's finished the loop (33 seconds) and I click anywhere on the form it apparently enters the loop again, then hangs so I have to manually close it from Windows.
There are no other objects on the …
Wow, that's easy. Thanks
In old QBasic I could use the LOG function to get the base-10 log of a number. So I would have something like this...
sglFormula = 150 - (LOG(intTemp + 10) * 30)
... the LOG function would give me the log base-10 of a variable (intTemp) plus 10.
How do I do this in VB.NET. Do I have to create my own log function and, if so, what would it look like?
Thanks
You can use
Exit While
,Exit For
,Exit Sub
, etc.
Thanks for that. As you can see, I'm not a pro at this.
Okay, but I only want to exit the loop when the user clicks the button again in whose click event the loop is running. (Sorry, hard for me to explain)
I'll try another way: The user clicks the button and that starts the loop. I want the loop to run until the user clicks the same button again. Then I want to exit the loop.
If I'm running a Do... Until or a For... Next loop in a button click event, is there a way I can allow the user to click the same button while the loop is running and escape the loop?
I'm trying to use the timer (not a Timer object) in a Do... Until loop. I want the loop to put a single variable into a label. When I do this it works and puts the value into the label (lblOxygenReading):
If btnGetOxygen.Text = "Get Oxygen Reading" Then
Select Case True
Case rdoColorWhite.Checked
strCurrentColor = "White"
Case rdoColorRed.Checked
strCurrentColor = "Red"
Case rdoColorBlue.Checked
strCurrentColor = "Blue"
Case rdoColorGreen.Checked
strCurrentColor = "Green"
Case rdoNoLight.Checked
strCurrentColor = "Dark"
End Select
Randomize()
sglOxygen = ((Rnd(1) * 0.2) + 0.9) * sglOxygen
lblOxygenReading.Text = sglOxygen.ToString("#.##")
btnGetOxygen.Text = "Start Timing"
Exit Sub
End If
But when I do the following (it's part of a code in a button click event), it doesn't put the sglOxygen value into the lblOxygenReading label:
If btnGetOxygen.Text = "Start Timing" Then
If strCurrentColor = "White" Then sglAdd = 0.13
If strCurrentColor = "Red" Then sglAdd = 0.058
If strCurrentColor = "Blue" Then sglAdd = 0.033
If strCurrentColor = "Green" Then sglAdd = 0.0
If strCurrentColor = "Dark" Then sglAdd = -0.033
Dim TimeNow As Date
Dim TimeLater As Date
Dim intWaitTime As Integer = 1
btnGetOxygen.Text = "Stop"
For l = 1 To 300
intWaitTime = 1 'number of seconds each
TimeNow = DateTime.Now
Do
TimeLater = DateTime.Now
lblOxygenReading.Text = sglOxygen.ToString("#.##")
'Loop Until DateDiff(DateInterval.Second, TimeNow, TimeLater) >= intWaitTime
'****************
'This section varies the size between 90% and 110%
Randomize()
sglAdd = ((Rnd(1) * 0.2) + 0.9) * sglAdd
'****************
sglOxygen = sglOxygen + sglAdd 'Adds to O2
If …
Thanks to Yorro. I didn't know how visibleChanged worked.
i dont get you......
like in Form1 you got like Button1 to go to Form2 Button 2 to go to Form3in Form2 u got a button1 to go back to form1 and button 2 to go to Form3
in Form3 u got a button1 to go back to form2 and button 2 to go back to
form 1?or something like that? cuz i dont get u
The reason for the buttons and forms is only practice to see how it works. The programs I will be writing require more than one form.
I have a project with more than one form and I move between them with a button click that hides the current form and shows the one I want. But what is I want to perform some procedure each time the form is shown? I tried this code on my Form2:
Private Sub Form2_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
MsgBox(testString)
End Sub
... to put a variable into MsgBox and, when I run the program, it works the first time the form is shown, but not when I go back to it from another form. Is there some other event handler I should be using?
Thanks... right you are.
Thanks for the explanation and the tip... I'll try that.
When I remove Me. from the variable, which is only declared in the module, I get the following warnings from Visual Studio:
Warning 1 The type for variable 'organisms' will not be inferred because it is bound to a field in an enclosing scope. Either change the name of 'organisms', of use the fully qualified name (for example, 'Me.organisms' or 'MyBase.organisms').
Warning 2 The type for variable 'organisminfo' will not be inferred because it is bound to a field in an enclosing scope. Either change the name of 'organisminfo', of use the fully qualified name (for example, 'Me.organisminfo' or 'MyBase.organisminfo').
Thanks for the explanation and the tip... I'll try that.
Thanks. Here's what I put in the module:
Module Module1
Public O As String
Public orgArray() As String
Public org(35, 4) As String
Public d As Integer = 32
Public organisms As Integer
Public organisminfo As Integer
Public i As Integer = 0
End Module
...and here's what's on Form1:
Public Class Form1
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PutOrganismDataIn:
'Puts data into one-dimensionsal array
'Dim O As String, orgArray() As String
O = "Smeglitious nobilis,monera,,s," _
& "Computicus garianus,monera,,s," _
& "Fastidyus hassica,monera,p,s," _
& "Diminutia scotia,protista,p,s," _
& "Strongellica sphinctius,protista,,s," _
& "Leigekonius dinero,protista,p,," _
& "Slumbricus cameronus,fungi,,," _
& "Conifera donaldi,fungi,,," _
& "Lasorderrico loco,fungi,,s," _
& "Reisus chaos,plant,p,," _
& "Wallius arizonica,plant,p,," _
& "Boggesnia ampulla,plant,p,," _
& "Pylorica thurlobius,animal,,," _
& "Drastium confusum,animal,,," _
& "Kathinius wispica,animal,,," _
& "Dibleria conus,monera,,s," _
& "Krelnius beautius,monera,,s," _
& "Bromlica graunus,monera,p,s," _
& "Pioneerica simia,protista,p,s," _
& "Mlefera grandia,protista,,s," _
& "Climficus uranus,protista,p,," _
& "Kladia mortia,fungi,,," _
& "Nerdius royalia,fungi,,," _
& "Blemius facia,fungi,,s," _
& "Scheterius krelmin,plant,p,," _
& "Ablimus californica,plant,p,," _
& "Robinsonius franka,plant,p,," _
& "Nametheria josepia,animal,,," _
& "Flarmica beautius,animal,,," _
& "Unermus blanca,animal,,," _
& "Querbica blondis,protista,p,," _
& "Blebnius clognica,plant,p,,"
orgArray = Split(O, ",") 'makes a new array splitting old _
' array (O) at commas
'MsgBox(orgArray(5)) 'Shows "monera" in message box
'MsgBox(orgArray(4)) 'Shows "Computicus garianus" in message box
ReadOrganismData:
'Following not necessary because declared as Public in Module
'Dim org(35, 4) …
I want to use more than one form in my project and be able to code a button or something that will do that. I tried this on Form1 and it worked.
Public Class Form1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Goes from this form to form 2
My.Forms.Form2.Show()
End Sub
End Class
BUT then I tried the following on Form2 to go back to Form1 and it doesn't work... the button does nothing.
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
My.Forms.Form1.Show() 'Doesn't work
End Sub
End Class
Also, when the user switches to a different form, will the variables assigned on the first form still be assigned on the second form (assuming they're declared as Public in the module?
I put some variable declarations in the module of my project. Of the six variables, two of them remained unavailable to the code on the form... I got an error message. Those two, which are within a FOR...NEXT loop have to be declared in the form code for the thing to run. I'm using "Public" to declare the variables in the module... is there some other way to declare them in the module so they'll be available even within a loop in a form? BTW I'm a real novice and don't really know what I'm doing.
I want tu use more than one form in my project and be able to code a button or something that will do that. I tried this on Form1 and it worked.
Public Class Form1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Goes from this form to form 2
My.Forms.Form2.Show()
End Sub
End Class
BUT then I tried the following on Form2 to go back to Form1 and it doesn't work... the button does nothing.
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
My.Forms.Form1.Show() 'Doesn't work
End Sub
End Class
Also, when the user switches to a different form, will the variables assigned on the first form still be assigned on the second form (assuming they're declared as Public in the module?
Thanks! Very cool, I found the module and put the variable declarations in there. Of the six variables, two of them remained unavailable to the code on the form... I got an error message. Those two, which are within a FOR...NEXT loop have to be declared in the form code for the thing to run. I'm using "Public" to declare the variables in the module... is there some other way to declare them so they'll be available even within a loop?
Thanks. I thought of that, but using Visual Studio, I can't find my way into the module of the project... it only shows me the form. I'm really new at this.
New to VB and using Visual Studio 2008. Trying to declare variables and arrays that can be used outside a specific procedure. I want to make the variable universally available within the program. I think I know how to do the declaration, I just can't find where in the code window to put it. Can't use PUBLIC within a procedure right?
Data IS static, so I'll try this. Thanks.
The READ command in old QBasic looked within the program itself, not an external file, for the "DATA" and read it in the order it appeared. So, in my old code below, the first READ d put the number 32 into the variable d. Then the READ within the FOR...NEXT loop put the rest of the DATA into the array.
So, how do put my "DATA" into the program itself, then have VB read the data into the two dimensional array?
(I know the syntax for the string variables in my old code are wrong for VB)
Thanks for any advice... as you can see, I am truly a novice.
In the mid-'90s I wrote in Quick Basic some lab simulations for science classes I was teaching. I want to rewrite them in VB and thought that I could just paste old QB code into VB... not so, of course.
I want to know how to read data from within the program into an array. Below is a sample of the old QBasic code I'm trying to duplicate.
DATA 32
'DATA is Name, kingdom, p for photosynthesis, s for single celled
DATA Smeglitious nobilis,monera,,s
DATA Computicus garianus,monera,,s
DATA Fastidyus hassica,monera,p,s
DATA Diminutia scotia,protista,p,s
DATA Strongellica sphinctius,protista,,s
DIM org$(5, 4)
ReadOrganismData:
READ d
FOR organisms = 1 TO d
FOR organisminfo = 1 TO 4
READ org$(organisms, organisminfo)
NEXT organisminfo
NEXT organisms
orgName = 1
Kingdom = 2
photo = 3
singleCelled = 4