Results 1 to 13 of 13

Thread: [2005] Messagebox question.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Location
    Howell, MI
    Posts
    134

    [2005] Messagebox question.

    Hi All!

    If I put into code something like:

    MsgBox(3 + 6 * 9)

    I get a messagebox with an answer, 57.

    How can I get the text out of a textbox or some other control and put it into a messagebox to do the same thing?

    Thanks.

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Messagebox question.

    Place 3 NumericUpDown controls on your form.
    VB.NET Code:
    1. MessageBox.Show(Cstr(NumericUpDown1.Value + NumericUpDown2.Value * NumericUpDown3.Value))
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Location
    Howell, MI
    Posts
    134

    Re: [2005] Messagebox question.

    OK.

    Not what I want. It is for my wife. I want a textbox that she can enter a long calculation into, i.e. - 3+6+4*8-9+6*7...., she does insurance work.

    I want to take that expression and put it into a messagebox to get the result. That is the easiest way to get the result of an expression. I don't want to write a bunch of code parsing this and that.

    Can this be done?

  4. #4
    Hyperactive Member cameron2's Avatar
    Join Date
    Mar 2008
    Location
    Australia
    Posts
    401

    Re: [2005] Messagebox question.

    Your best off doing what Atheist said unless you want to make a textbox for each number in the calculation.
    The best way to do what your trying to do is to make a calculator or use the one provided by windows.
    If this post helped you, please click the rate button to say thank you! Remember to mark the thread as resolved too.
    Autoclicker, Hide Taskbar, Sounds on internal speaker, Changing Start Button Text (with code)

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Location
    Howell, MI
    Posts
    134

    Re: [2005] Messagebox question.

    That is exactly what I am trying to do, make a calculator. One that will take 5 or 6 expressions at one time and has a checkbox to be the topmost form. I am trying to be lazy by just dumping the expression into messagebox, but I can't figure out how to convert the string to something that messagebox likes.

  6. #6
    Hyperactive Member cameron2's Avatar
    Join Date
    Mar 2008
    Location
    Australia
    Posts
    401

    Re: [2005] Messagebox question.

    If your putting the equation in one textbox then you must calculate this equation and store it in a variable such as result and then have a messagebox display result: msgbox(result).
    If this post helped you, please click the rate button to say thank you! Remember to mark the thread as resolved too.
    Autoclicker, Hide Taskbar, Sounds on internal speaker, Changing Start Button Text (with code)

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Location
    Howell, MI
    Posts
    134

    Re: [2005] Messagebox question.

    Well, I can put the equation directly in code into a messagebox and it calculates the answer. That is what I want. I don't want to write the code to do the calculation, messagebox will do it for me if I can convert the string to something it likes.

  8. #8
    Hyperactive Member cameron2's Avatar
    Join Date
    Mar 2008
    Location
    Australia
    Posts
    401

    Re: [2005] Messagebox question.

    I've found something promising but not sure how to use it:
    Msgbox(textbox1.text.sum"put the arguments here")
    But i have no idea what to put in the arguments, have a search on google of that function.
    If this post helped you, please click the rate button to say thank you! Remember to mark the thread as resolved too.
    Autoclicker, Hide Taskbar, Sounds on internal speaker, Changing Start Button Text (with code)

  9. #9
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    Re: [2005] Messagebox question.

    In this case the simplification you want is really making the problem much harder, as in anti-simplification.
    By doing it this way, you'll have to first split the string entered in the textbox into it's individual parts. Then you'll have to detect the pluses, minuses etc.; separate those from the numbers and then perform the indicated operations.
    That's far more complicated than it needs to be.
    An alternative would be to just enter one number into each of multiple textboxes.
    Since you are looking for speed, I would suggest maybe one box to enter numbers into. After a number is entered she can enter an operator off of her keypad (or whatever is available). Upon the program detecting a keystroke of an operator your program would check the textbox value to see if it is an allowed entry (a number). Next you would save the indicated operation in any number of ways and simultaneously clear the textbox. When the next number is entered, the indicated operation would be performed on those two numbers and, again, the textbox would be cleared.
    I think that should somewhat simplify the code and come closer to the order of operations that you desire to set up for her.
    There are no doubt other methods that might prove to be also easier than your first suggestion.

  10. #10
    Hyperactive Member cameron2's Avatar
    Join Date
    Mar 2008
    Location
    Australia
    Posts
    401

    Re: [2005] Messagebox question.

    Yes as fourblades suggested you have two options: have one textbox and do comlicated stuff like splitting it, detecting wats in it and stuff or having a number of textboxes for each number that you want to calculate.
    If this post helped you, please click the rate button to say thank you! Remember to mark the thread as resolved too.
    Autoclicker, Hide Taskbar, Sounds on internal speaker, Changing Start Button Text (with code)

  11. #11
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] Messagebox question.

    it can be done using the CodeDomProvider class.

    you could pass it a string, i.e. "msgbox(" & textbox1.text & ")", which you could then compile + run. but i don't know how you would do that. its an advanced topic

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] Messagebox question.

    try this. it works but intellisense recommends using CodeDomProvider class.

    vb.net Code:
    1. Imports Microsoft.VisualBasic
    2. Imports System.CodeDom.Compiler
    3.  
    4. Public Class Form1
    5.  
    6.     Private Sub cmdCompile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCompile.Click
    7.         ' Create the compiler.
    8.         Dim VB As New VBCodeProvider()
    9.         Dim Compiler As ICodeCompiler = VB.CreateCompiler()
    10.  
    11.         ' Define some parameters.
    12.         ' In this case, we choose to save the assembly file to a file.
    13.         Dim Param As New CompilerParameters()
    14.         Param.GenerateExecutable = True
    15.         Param.OutputAssembly = "TestApp.exe"
    16.         Param.IncludeDebugInformation = False
    17.  
    18.         ' Add some common assembly references (based on the currently running application).
    19.         Dim Asm As System.Reflection.Assembly
    20.         For Each Asm In AppDomain.CurrentDomain.GetAssemblies()
    21.             Param.ReferencedAssemblies.Add(Asm.Location)
    22.         Next
    23.  
    24.         ' Compile the code.
    25.         Dim Results As CompilerResults = Compiler.CompileAssemblyFromSource(Param, txtCode.Text)
    26.  
    27.         ' Check for errors.
    28.         If Results.Errors.Count > 0 Then
    29.             Dim Err As CompilerError
    30.             Dim ErrorString As String
    31.             For Each Err In Results.Errors
    32.                 ErrorString &= Err.ToString()
    33.             Next
    34.             MessageBox.Show(ErrorString)
    35.         Else
    36.             ' Launch the new application.
    37.             Dim ProcessInfo As New ProcessStartInfo("TestApp.exe")
    38.             ProcessInfo.WindowStyle = ProcessWindowStyle.Hidden
    39.             Process.Start(ProcessInfo)
    40.         End If
    41.  
    42.     End Sub
    43.  
    44. End Class
    Attached Images Attached Images  

  13. #13
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: [2005] Messagebox question.

    There are lot of decent expression evaluators out there. Here's one from the Code Project:
    http://www.codeproject.com/KB/vb/mat...evaluator.aspx
    "It's cold gin time again ..."

    Check out my website here.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width