|
Ultima Reborn wrote: How to create a MsgBox that allows me to load another form when i click yes and when i click no it closes program?
You need to not use MSgBox if you're using VB.NET. Use MessageBox.Show, which has a parameter to specify what buttons you show, and then you can check the DialogResult that is returned to decide which action to take.
Ultima Reborn wrote: Also how do i do a global variable becauase i cant reset my 'rlmemory' sum back to 0 from another form or can I?
You can't. Global variables are generally a bad idea. You can create what you want with a public shared variable, but I'd advise against it.
Ultima Reborn wrote: becauase i cant reset my 'rlmemory' sum back to 0 from another form or can I?
I have no idea what your rlmemory sum is, but I assume it's an int or something. You can use delegates for inter form communication. You can also make it shared, if there's only one within the app. Also, if your form that contains the value is a child of the form that wants to change it, you can do it directly.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
You can use MsgBox. Try this:
<br />
MsgBox("Text here", MsgBoxStyle.YesNo)<br />
If DialogResult = Windows.Forms.DialogResult.Yes Then<br />
FormName.Show()<br />
Else<br />
Me.Close()<br />
End If<br />
|
|
|
|
|
Uhhh...what? Where is DialogResult going to get set?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Correction to my last post, a small code mistake. Try this instead:
<br />
MsgBox("Text Goes Here.", MsgBoxStyle.YesNo)<br />
If System.Windows.Forms.DialogResult.Yes = Windows.Forms.DialogResult.Yes Then<br />
FormName.Show()<br />
End If<br />
You do not need to have a IF statement for the "No" button.
|
|
|
|
|
This still won't work. Your comparing an Enum value to itself which will ALWAYS return TRUE!!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
ok thanks for the message box help
So how do i get the "no" button to do a different procedure?
for it i have
MsgBox("Message", MsgBoxStyle.YesNo)
If System.Windows.Forms.DialogResult.Yes = Windows.Forms.DialogResult.Yes Then
txtTotal.Text = CStr(rlMemory)
Form2.txtTotalCost.Text = CStr(rlMemory)
Form2.txtDiscount.Clear()
Form2.Show()
End If
for that variable thing i have
Dim intNights As Integer
Dim rlPrice As Single
Dim rlTotal As Single
Dim rlMemory As Single
basically rlMemory stores the data i need, but at the end of the program when u get a diaglog box giving you the option to restart the program, at this point i need the rlmemory to go back to 0.
-- modified at 16:40 Tuesday 17th October, 2006
|
|
|
|
|
Here is how you should do it:
<br />
Dim BoxCall As MsgBoxResult<br />
BoxCall = MsgBox("Message", MsgBoxStyle.YesNo)<br />
If BoxCall = MsgBoxResult.Yes Then<br />
If System.Windows.Forms.DialogResult.Yes = Windows.Forms.DialogResult.Yes Then<br />
txtTotal.Text = CStr(rlMemory)<br />
Form2.txtTotalCost.Text = CStr(rlMemory)<br />
Form2.txtDiscount.Clear()<br />
Form2.Show()<br />
Else<br />
'Code for "No" goes here. Leave blank if no procedure is needed.<br />
End If<br />
And you said that you want rlmemory to go to 0? If so, then use this:
rlmemory = "0" .
Hope this helps.
|
|
|
|
|
UltraCoder wrote: rlmemory = "0".
Assuming it is a string. I'd have assumed otherwise.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Have you noticed anything weird about the two if statements in the post you replied to?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
with the messagebox i have
Dim BoxCall As MsgBoxResult
BoxCall = MsgBox("Message", MsgBoxStyle.YesNo)
If BoxCall = MsgBoxResult.Yes Then
If System.Windows.Forms.DialogResult.Yes = Windows.Forms.DialogResult.Yes Then
txtTotal.Text = CStr(rlMemory)
Form2.txtTotalCost.Text = CStr(rlMemory)
Form2.txtDiscount.Clear()
Form2.Show()
Else
Form4.txtTotalCost.Text = CStr(rlMemory)
Form4.Show()
End If
End If
but form 4 doesnt show =z
well i tried using rlmemory = "0" but it doesnt reconise it as its on another form also i did have it in the form load but didnt seem to work if i wanted to re add something
Example of what program does
(working in down structure)
Menu (form)
calculation (form) <--input data \ calculate it
total (form) <-- takes final sum and has it on a new form with do u want to do calculation again
-- modified at 21:00 Tuesday 17th October, 2006
|
|
|
|
|
Ok, for one, remove "If System.Windows.Forms.DialogResult.Yes = Windows.Forms.DialogResult.Yes Then" and then the duplicate "End IF" at the bottom, (A small mistake on my part).
For the "No", use the same procedure as "Yes". Example:
<br />
If BoxCall = MsgBoxResult.No Then<br />
'Code Goes Here<br />
End If<br />
And as for clearing the "rlmemory" varible, try rlmemory = 0 , or if the varible is in another form, you might have to use something like a setting to hold the varible..
I hope this helps. If not, you could try posting the code for "rlmemory" (setting/removing values etc.)
|
|
|
|
|
Ultra,
1) Ultra coder seemingly is testing the same enum against itself which is not giving you your answer. System library is implied that's why you do not have to use the 'import' key word in most cases.
If MsgBox("text goes here", MsgBoxStyle.Question + MsgBoxStyle.YesNo + _
MsgBoxStyle.DefaultButton2,"form title") = MsgBoxResult.Yes Then
Dim oFrm as new Form2
oFrm.ShowDialog
oFrm.Dispose
oFrm = Nothing
Else
Close()
End If
2) Instead of telling you that it's a bad idea. no one seemingly answered your question. "how do i do a global variable". You do this by creating module file (old bas extension) and adding a public variable in there. Because a module is considered public by all files in your project, the variable is available from every piece of code.
Module basMain
public gsValue as string '<--- global variable
End Module
'now you can update or ask for the value of the variable anywhere
class form1
private sub ShowMeValue
msgbox gsValue
end sub
end class
3) You asked if you can update a variable of one form from another. There are a lot of methods that are not the most desirable but saying that "you can't" is not correct. Were there's a will there's a way. One way is to pass the pointer of the form1 into form2 via a routine.
class form1
public msVariable as string
private sub CallAnotherForm
Dim oFrm as new form2
ofrm.ExecuteMethod(me) '<---
ofrm.showdialog
ofrm.dispose
ofrm = nothing
end sub
End Class
class form2
public sub ExecuteMethod(oFrm as form1)
oFrm.msVariable="Hello" 'you just updated the variable of form1
End Sub
end class
Hope this helps...
Nathan
|
|
|
|
|
I have tried this method and it does not work! The method I posted works fine!
|
|
|
|
|
It works because you only tested one case for your if statements. They ALWAYS return True because, in essence, you did this: If 2 = 2 Then ... .
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks Dave, that was the attempt of my point.
Just because you leave off "system" doesn't tie the enum to the result of the msgbox. you need to test what the msgbox is returning.
nathan
|
|
|
|
|
Hi Members
I need some info regarding how to create a hotkey for application with combination of letters or numbers e.g Ctrl + 1234
Regards
|
|
|
|
|
Windows doesn't support such combinations. You have to use a single letter or number.
Now, if you were to write your own service, complete with a global keyboard hook, and tracking which keys were hit and released, then its possible.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Select the "ShortcutKeys" option in the Control's properties. From there you can change the ShortcutKeys. Doing so by code doesn't work right.
|
|
|
|
|
Nice, but it won't work with multiple keys in the combination. Only one key is allowed - Ctrl-A, Ctrl-5 - not Ctrl-123 or Ctrl-A3b.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I have created a folder for a specific location in vb.net but I want to automatically generate the folder name as the current date when it is created. If anyone know any code to do this please let me know ASAP. Thanks!
jds1207
|
|
|
|
|
Well, to name the directory for the current date, then try this:
<br />
Dim DirName As String = "C:\" + DateTime.Today<br />
My.Computer.FileSystem.CreateDirectory(DirName)<br />
Or, to name directory for the current date and time, try this:
<br />
Dim DirName As String = "C:\" + My.Computer.Clock.LocalTime<br />
My.Computer.FileSystem.CreateDirectory(DirName)<br />
|
|
|
|
|
Converting a Date to a string is very easy. All you have to do is supply a format string to the ToString() method and you've got your directory name.
Dim dirName As String = DateTime.Now.ToString("MM-dd-yyyy")
Then you just combine that with the parent path the you want to create that directory in:
Imports System.Io
.
.
.
Dim fullPath As String = Path.Combine(Application.StartupPath, dirName)
Directory.CreateDirectory(fullPath)
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thank you very much! Now how do you add the time to the name also?
|
|
|
|
|
Just use:
<br />
Dim dirName As String = DateTime.Now.ToString("M-d-yyyy hh.mm.ss tt")<br />
or without am/pm:
<br />
Dim dirName As String = DateTime.Now.ToString("M-d-yyyy hh.mm.ss")<br />
-- modified at 2:38 Wednesday 18th October, 2006
|
|
|
|
|
Whoa there! You better start thinking before you start posting code. Slashes and colons are not legal in file or directory names.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|