Extracting Variables from Strings and Event for a Tabchange in a TabControl

I have a program that is meant to take a user defined string (ex. x2 + 2x + 1) and divide it, and then store those values (the coefficents of x); there is a practically indefinite number of numbers in the coefficient.

I've looked at the String.Split Method, but I don't understand it very well nor do I believe it's very practical when you have to keep splitting each variable to get the coefficient. Is there an easier way to the the opposite of concatenation

---

Unrelated to my previous question, I also need to have some things(generate a MsgBox and set variable values) when the tab of a tab control is changed. I've read about what I believe is the event, but once again, I am not totally sure how to use it because I am not familiar with raising events. How would I go about doing this




Answer this question

Extracting Variables from Strings and Event for a Tabchange in a TabControl

  • milTash

    No, it's not solved...

    I still don't know an efficient way to extract the variables from the textbox's text.



  • Giusy Provvidenti

     

     

    you don't have to raise the event the control will.

    You do, however have to declare the event handler.

    in edit mode...

    In the upper left hand window, select the tab control. Then in the right hand window, select the selectionchanged event. This will insert the event handler in your source code for you to code.



  • alok ranjan

    Specifically, what I want to have is code that takes a string entered into a textbox such as

    9x2 + 8x + 7

    In my program, I need to take the number from this string and store it as a variable for computation. The pieces "x2 + " and "x + " always remain constant. Is there code that will do this for me and if so what is it



    Before I was speaking about a command that I had read a little bit about: String.Split. However, from what I do understand about it, it would take numerous lines of code to do the one seemingly simple task that I need it do.

    http://users.cjb.net/jontec7/quadratic%20equation.exe




  • Tamoxifeno

    hi,

    Is your problem solved

    Thank you,
    Bhanu.



  • Malla

    I researched regex, and it looks like exactly what I need. However, I did not see any Visual Basic examples in the explanation. I had to look at the C++ end to understand what they were talking about (I don't know C++!).

    Regex.Replace had an example and it looks like it just about solves my problem, except for the fact that it would return (as in our first example) 987, which is not anything that I could work with.

    Does anyone have any ideas about this Is there another Regex.* that I can use


  • Varsha

    Here's what I think that I am going to do.

    We start out with the input: 9x2 + 8x + 7.
    I use Regex.Replace to get rid of the spaces " " and the Xs "x".
    It returns: 9+8+7

    From here I use the String.Split to return an array of 9, 8, 7.

    Finally
    array(0) is stored as variable (integer) a
    array(1) is stored as variable (integer) b
    array(2) is stored as variable (integer) c

    And with these variables I can do the computation that I need.
    I'll reply back with my result and the code that I use.


  • Jvalente

    maybe you can try using regular expression
    just check out System.Text.RegularExpressions

    regular expression(or regex) gives much more flexibilities in text manipulations
    but it has a somewhat steep learning curve for beginners



  • Francy

    You need a beast called Bison to parse expressions like this. Google for Yacc and Lex.


  • Margriet

    Hi jon,

    your first question is not so clear.Somewhere i can't understand english like this "but I don't understand it very well nor do I believe it's very practical ".

    can you please explain in simple english what you want exactly

    and for second question. I hope you already got Ans.

    msgbox("Tab page changed") insteed of you can use

    Messagebox.Show("Tab page changed")



  • Extracting Variables from Strings and Event for a Tabchange in a TabControl