Need help with coding.. Im stuck.... Please help need answered ASAP... Textbox Question

Gesperrt Need help with coding.. Im stuck.... Please help need answered ASAP... Textbox Question

  • Dienstag, 28. Februar 2012 22:45
     
     

    OK I was wondering how I can make this happen. I am making a app that basically is going to help me input things on a website faster. I am using Visual Studio 2010 Ultimate. I have a text box that has some of these fields on the side:


    |membersonly=
    |power=
    |gender=
    |race=
    |job=
    |minlevel=
    |minrank=
    |slot=
    |notrade=
    |nosell=

    Here is a link to a picture of my application: My Picture

    I have a bunch of fields that correspond with each part. How do I make it so that when I fill in a field it gets added onto the right line.

    Like if I click the checkbox for members only it adds a "y" after the |membersonly=

    And if I choose the number 1 of the radio buttons in power it would put a number one next to the |power=    

    Also in the end I would like the Save button to copy the text in the textbox (the way it is) to the clipboard so that I could paste in on the website.

Alle Antworten

  • Dienstag, 28. Februar 2012 23:08
     
      Enthält Code

    On the event of whatever you're doing on the form, something as simple as this should work:

    *This is just giving you an idea*

    Dim strValue As String = "lkjljkj" 'This can be the value of the radiobutton value or a textbox value, etc..
     
            For Each ln As String In TextBox1.Lines
                Select Case 0
                    Case ln.IndexOf("|race=")
                        TextBox1.Text = TextBox1.Text.Replace(ln, "|race=" & strValue)
                End Select
            Next

    That case statement is basically like checking to see if the textbox line starts with "|race" or "|whatever", and if it's the line you want, then we change it.

    Cheers 


    If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
    ~ "The universe is an intelligence test." - Timothy Leary ~



  • Dienstag, 28. Februar 2012 23:35
     
      Enthält Code

    On the event of whatever you're doing on the form, something as simple as this should work:

    *This is just giving you an idea*

    Dim strValue As String = "lkjljkj" 'This can be the value of the radiobutton value or a textbox value, etc..
     
            For Each ln As String In TextBox1.Lines
                Select Case 0
                    Case ln.IndexOf("|race=")
                        TextBox1.Text = TextBox1.Text.Replace(ln, "|race=" & strValue)
                End Select
            Next

    That case statement is basically like checking to see if the textbox line starts with "|race" or "|whatever", and if it's the line you want, then we change it.

    Cheers 


    If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
    ~ "The universe is an intelligence test." - Timothy Leary ~



    Im a little noobish with visual basic. Im having a little trouble understanding.

    1. What would go in the As String = "lkjlkjlkj"???

    2. What would I put this under... I named the text box on the right as txtitem.

    3. Would a combo box be different?

    Sorry lol... Im somewhat good at design but I need to learn coding better.


  • Dienstag, 28. Februar 2012 23:35
     
     

    1. Textbox1.Text, RadioButton1.Text, etc...

    2. Change Textbox1.Text to txtitem.Text then in my code, and this also would depend on what event you want to trigger the changes with; button click?

    3. No, the same: Combobox1.SelectedItem will produce the selected item string value.

    Cheers :)


    If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
    ~ "The universe is an intelligence test." - Timothy Leary ~

  • Dienstag, 28. Februar 2012 23:58
     
     

    1. Textbox1.Text, RadioButton1.Text, etc...

    2. Change Textbox1.Text to txtitem.Text then in my code, and this also would depend on what event you want to trigger the changes with; button click?

    3. No, the same: Combobox1.SelectedItem will produce the selected item string value.

    Cheers :)


    If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
    ~ "The universe is an intelligence test." - Timothy Leary ~

    Ahh it worked lol... Race works now... Do I have to make a Dim string for each field????

    And quick question about the radio buttons... how do I make it so that if they choose the white radio button instead of putting white next to |tier= it would be just the letter w

    I appreciate the help XD


    • Bearbeitet Tythesly1 Dienstag, 28. Februar 2012 23:59
    • Bearbeitet Tythesly1 Mittwoch, 29. Februar 2012 00:05 question
    •  
  • Mittwoch, 29. Februar 2012 00:23
     
      Enthält Code

    Cheers friend :)

    >>Ahh it worked lol... Race works now... Do I have to make a Dim string for each field????

    What do you mean by this?

    >>And quick question about the radio buttons... how do I make it so that if they choose the white radio button instead of putting white next to |tier= it would be just the letter w

    Define your own value then for each RadioButton

    If WhiteRadioButton.Checked Then
                'Append only w here after the radiobutton entry in the textbox
            Else
                'Do something else or add more Radiobuttons here to check for
            End If


    If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
    ~ "The universe is an intelligence test." - Timothy Leary ~


  • Mittwoch, 29. Februar 2012 00:33
     
      Enthält Code

    >>Ahh it worked lol... Race works now... Do I have to make a Dim string for each field????

    What do you mean by this?

    I mean that I put Dim strValue As String = comrace.SelectedItem

    Would i need to make a Dim strValue1 As String = comgender.SelectedItem?

    >>And quick question about the radio buttons... how do I make it so that if they choose the white radio button instead of putting white next to |tier= it would be just the letter w

    Define your own value then for each RadioButton

    If WhiteRadioButton.Checked Then
                'Append only w here after the radiobutton entry in the textbox
            Else
                'Do something else or add more Radiobuttons here to check for
            End If

    Am I confused about what you mean above X(

    How do I append and is this is still under the button click event?


  • Mittwoch, 29. Februar 2012 00:44
     
     

    >>How do I append and is this is still under the button click event?

    If you want it to be... Doesn't have to be there though, but it's essentially using the same idea as above.

    Are you trying to add ALL of the data throughout the form at once to the values on the right by a button click?


    If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
    ~ "The universe is an intelligence test." - Timothy Leary ~

  • Mittwoch, 29. Februar 2012 00:48
     
     

    >>How do I append and is this is still under the button click event?

    If you want it to be... Doesn't have to be there though, but it's essentially using the same idea as above.

    Are you trying to add ALL of the data throughout the form at once to the values on the right by a button click?


    If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
    ~ "The universe is an intelligence test." - Timothy Leary ~

    Are you trying to add ALL of the data throughout the form at once to the values on the right by a button click?....... Yes lol.... At first I was hoping it was possible for it to change either as soon as its typed into the text box or as soon as it gets selected from a combo box. And the only button I was going to use was to save all the text in the text box to the clipboard so I could paste it on the website.
  • Mittwoch, 29. Februar 2012 00:57
     
      Enthält Code

    >>At first I was hoping it was possible for it to change either as soon as its typed into the text box or as soon as it gets selected from a combo box

    It is though (possible), but in the case of just a single button, then complete my case statement above.

    Dim strValue As String = "lkjljkj" 'This can be the value of the radiobutton value or a textbox value, etc..
     
            For Each ln As String In TextBox1.Lines
                Select Case 0
                    Case ln.IndexOf("|race=")
                        TextBox1.Text = TextBox1.Text.Replace(ln, "|race=" & strValue)
                    Case ln.IndexOf("|membersonly=")
                        'Textbox/Radiobutton/Checkbox value here using the method in the first Case
                    Case ln.IndexOf("|power=")
                        If WhiteRadioButton.Checked Then
                            'Append only w here after the radiobutton entry in the textbox
                        ElseIf SomeOtherRadioButton.Checked Then
     
                        Else
                            'Do something else or add more Radiobuttons here to check for
                        End If
                    Case ln.IndexOf("|gender=")
                        'Code here
                    Case ln.IndexOf("|race=")
                        'Code here
                    Case ln.IndexOf("|job=")
                        'Code here
                    Case ln.IndexOf("|minlevel=")
                        'Code here
                    Case ln.IndexOf("|minrank=")
                        'Code here
                    Case ln.IndexOf("|slot=")
                        'Code here
                    Case ln.IndexOf("|notrade=")
                        'Code here
                    Case ln.IndexOf("|nosell=")
                        'Code here
                End Select
            Next

    Cheers :)


    If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
    ~ "The universe is an intelligence test." - Timothy Leary ~


  • Mittwoch, 29. Februar 2012 04:31
     
      Enthält Code

    Dim
     strValue As String = "lkjljkj" 'This can be the value of the radiobutton value or a textbox value, etc..         For Each ln As String In TextBox1.Lines             Select Case 0                 Case ln.IndexOf("|race=")                     TextBox1.Text = TextBox1.Text.Replace(ln, "|race=" & strValue)                 Case ln.IndexOf("|membersonly=")                     'Textbox/Radiobutton/Checkbox value here using the method in the first Case                 Case ln.IndexOf("|power=")                     If WhiteRadioButton.Checked Then                         'Append only w here after the radiobutton entry in the textbox                     ElseIf SomeOtherRadioButton.Checked Then                     Else                         'Do something else or add more Radiobuttons here to check for                     End If                 Case ln.IndexOf("|gender=")                     'Code here                 Case ln.IndexOf("|race=")                     'Code here                 Case ln.IndexOf("|job=")                     'Code here                 Case ln.IndexOf("|minlevel=")                     'Code here                 Case ln.IndexOf("|minrank=")                     'Code here                 Case ln.IndexOf("|slot=")                     'Code here                 Case ln.IndexOf("|notrade=")                     'Code here                 Case ln.IndexOf("|nosell=")                     'Code here             End Select         Next
    Thank you so much!!!!!! Ive gotten everything done except that last part... the extra section is meant to add lines to the textbox. Like if Talent is chosen from the combobox then it would add the line |talent= and whatever gets added to the textbox next to it would be put next to the equals sign... I know how to put the textbox text in (thanks to you :D) but how to I make it so that it addes lines?
  • Mittwoch, 29. Februar 2012 06:24
     
      Enthält Code

    You should not try to update the textbox 'on the fly'.  Maintain your data separately from the text box display.  Change it in the event that indicates it has changed, and refresh your display of the whole data when anything changes. 

    The data should be an array of string.   Assume it is called lines.  Array elements 0 and 17 never change.  The others may change. 

        Dim lines() As String = {"{{FRitem", "|tier=", "|memberonly=", "|description", "|spawn", "|sc", "|power", "|gender", "|races", "|jobs"} 'etc
    

    When a change occurs, update the item that is being changed. For instance, when someone types in the gender box, the array element will be changed like this:

        Private Sub txtGender_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtGender.TextChanged
            lines(7) = "|gender=" & txtGender.Text
        End Sub

    When any change is completed, the text box is updated:

        Private Sub txtGender_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtGender.Leave
            txtAllLines.Text = ""
            For I As Integer = 0 To 9
                txtAllLines.Text &= lines(I) & vbCrLf
            Next
        End Sub

    That last example should be in one function that is called any time a change is completed. For some controls, such as a check box, the refresh can occur for every change.  For others, such as the text box example above, you can choose to process each character as it changes (as the above example), or do the whole change in the leave event.  

    Trying to find items from the text box and trim off existing values and update them and reinset intot he right location and so on is just too complex. 

  • Mittwoch, 29. Februar 2012 08:00
     
      Enthält Code

    @Acamar - Very true, however, if you want to go that way, why use a loop? String.Join() is much faster as well

    lines(0) = "|membersonly=" & "testing"
    lines(1) = "|power=" & "testing"
    lines(2) = "|gender=" & "testing"
    lines(3) = "|race=" & "testing"
    lines(4) = "|job=" & "testing"
    lines(5) = "|minlevel=" & "sdfsdfsd"
    lines(6) = "|minrank=" & "testing"
    lines(7) = "|slot=" & "testing"
    lines(8) = "|notrade=" & "testing"
    lines(9) = "|nosell=" & "testing"
     
    TextBox1.Text = String.Empty
    TextBox1.Text = String.Join(vbCrLf, lines)

    @OP - Acamar is right in this case, I actually think his method is better, although I would go with String.Join() to concat the items in the array to avoid the loop and increase the speed of the process as well. Remember the values set in each index of the array and change them accordingly, then set the array to the textbox.text value when you want to update it.

    Cheers :)


    If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
    ~ "The universe is an intelligence test." - Timothy Leary ~



  • Mittwoch, 29. Februar 2012 14:11
     
      Enthält Code

    @Acamar - Very true, however, if you want to go that way, why use a loop? String.Join() is much faster as well

    lines(0) = "|membersonly=" & "testing"
    lines(1) = "|power=" & "testing"
    lines(2) = "|gender=" & "testing"
    lines(3) = "|race=" & "testing"
    lines(4) = "|job=" & "testing"
    lines(5) = "|minlevel=" & "sdfsdfsd"
    lines(6) = "|minrank=" & "testing"
    lines(7) = "|slot=" & "testing"
    lines(8) = "|notrade=" & "testing"
    lines(9) = "|nosell=" & "testing"
     
    TextBox1.Text = String.Empty
    TextBox1.Text = String.Join(vbCrLf, lines)

    @OP - Acamar is right in this case, I actually think his method is better, although I would go with String.Join() to concat the items in the array to avoid the loop and increase the speed of the process as well. Remember the values set in each index of the array and change them accordingly, then set the array to the textbox.text value when you want to update it.

    Cheers :)


    If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
    ~ "The universe is an intelligence test." - Timothy Leary ~



    Remember guys... Im not that experienced with coding... Im trying to learn and understand, but its a little confusing.

    1. Can somebody explain Acamars post? Its a little hard to understand.

    2. What does String.Join() do and mean?

    3. So how do I add lines lol?

  • Mittwoch, 29. Februar 2012 16:02
     
     

    I am using Visual Studio 2010 Ultimate.

    Over here that costs about £10,000 (about $16,000).

    If I had paid that amount for a piece of software I'd spend a bit of time learning how to use it.

  • Mittwoch, 29. Februar 2012 16:07
     
     
    Yeah, maybe there was no money left for a F1 key.  

    Armin

  • Mittwoch, 29. Februar 2012 16:17
     
     

    I am using Visual Studio 2010 Ultimate.

    Over here that costs about £10,000 (about $16,000).

    If I had paid that amount for a piece of software I'd spend a bit of time learning how to use it.


    I acutally got it for free... because im going for a computer technology degree I can get any microsoft software for free... Except Office 2010 at the moment lol. Only catch is that I need to stay in college to be able to renew the license each year.
  • Mittwoch, 29. Februar 2012 20:56
     
     Beantwortet Enthält Code

    Create an array of string that contains the 18 lines of text that is in the text box. This is the whole text, even though some of those lines are not being changed.  This is re-created from your image and therefore may be wrong.

        Dim lines() As String = {"{{FRitem", _
                                 "|tier=", _
                                 "|memberonly=", _
                                 "|description", _
                                 "|spawn", _
                                 "|sc", _
                                 "|power", _
                                 "|gender", _
                                 "|races", _
                                 "|job", _
                                 "|minlevel", _
                                 "|minrank", _
                                 "|slot", _
                                 "|notrade", _
                                 "|nosell", _
                                 "|unlimited", _
                                 "|coinshop", _
                                 "|}}"}

    Create a routine you can use to display the current state of the text at any time.  Ignore  join - just use a simple loop for now.  Those sorts of improvements can be implemented at any time after you get your code working properly.

        Private Sub ShowText(ByVal L() As String)
            txtAllLines.Text = ""
            For I As Integer = 0 To 9
                txtAllLines.Text &= L(I) & vbCrLf
            Next
        End Sub

    You will call this routine at the start of your program to show the text (stubs only) before any changes have been made.  You will also call it immediately after the user makes any change to one of the items in the list. 

    For text items. like Description, you can use the text changed event of the text box to record each character as it is typed, or you can use the Leave event to indicate when all the text has been entered. For text changed it would be

        Private Sub txtDescription_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDescription.TextChanged
            lines(2) = "|description=" & txtDescription.Text
            ShowText(lines)
        End Sub

    For a combobox such as gender the selected index changed event indicates that something has changed, so it it would be

        Private Sub cbxGender_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxGender.SelectedIndexChanged
            lines(7) = "|gender=" & cbxGender.Text
            ShowText(lines)
        End Sub

    For a checkbox it might be this:

        Private Sub chkNoTrade_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkNoTrade.CheckedChanged
            If chkNoTrade.Checked Then
                lines(13) = "|notrade=y"
            Else
                lines(13) = "|notrade=n"
            End If
            ShowText(lines)
        End Sub

    Just repeat that structure (rebuild the line, show all the lines) for each change that the user can make, using the appropriate line number and text for the item being changed, and selecting the event of the control that tells you the change has been made.  How you handle the power or unlimited items depends on how you have arranged the radio buttons - you can work that out after the basic structure is in place.

    If you use this process there is no need to add a line - the stub for each line already exists, and you are only making changes by appending text to the end of each line. If that's not the way it works, you will need to indicate just what you mean by 'add lines'.

    • Als Antwort vorgeschlagen AceInfinityMVP Mittwoch, 29. Februar 2012 22:42
    • Als Antwort markiert Tythesly1 Donnerstag, 1. März 2012 21:46
    •  
  • Mittwoch, 29. Februar 2012 22:18
     
      Enthält Code
        Dim lines() As String = {"{{FRitem", _
                                 "|tier=", _
                                 "|memberonly=", _
                                 "|description", _
                                 "|spawn", _
                                 "|sc", _
                                 "|power", _
                                 "|gender", _
                                 "|races", _
                                 "|job", _
                                 "|minlevel", _
                                 "|minrank", _
                                 "|slot", _
                                 "|notrade", _
                                 "|nosell", _
                                 "|unlimited", _
                                 "|coinshop", _
                                 "|}}"}

    If you use this process there is no need to add a line - the stub for each line already exists, and you are only making changes by appending text to the end of each line. If that's not the way it works, you will need to indicate just what you mean by 'add lines'.

    What I meant by adding lines is that some items give extra stats while others do not. Instead of showing each stat field like(which takes up space):

    |talent=

    |health=

    |toughness=

    I would like it to add the field when its chosen from the combo box.

    So if they chose Energy and typed 36 in the textbox next to it, it would put:

    |energy=36

    Or if they chose Abilities (which pops up two textboxs.. I got that to work) and typed Ice Arrow in one and Blizzard Barrage in the other,then it would put:

    |abilities=Ice Arrow, Blizzard Barrage



    • Bearbeitet Tythesly1 Mittwoch, 29. Februar 2012 22:54 I figured out the radio buttons
    •  
  • Mittwoch, 29. Februar 2012 22:45
     
     

    I proposed Acamar's answer as the answer. Mostly because it's the easiest to manage, he's storing the values of each line into an array, and as long as you keep tabs on which index resides to which line, it can be easily interchanged with a line and particular value that you want. Instead of the iteration through the array for each line though in what Acamar suggested, I proposed the addition of using String.Join() instead to join each element of the array with the separator of a new line feed, which is what that line in my modified code does. It's also a bit faster than looping through, but Acamar there has a good idea if you want something that is easily manageable.

    Cheers :)


    If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
    ~ "The universe is an intelligence test." - Timothy Leary ~

  • Mittwoch, 29. Februar 2012 23:26
     
     

    I proposed Acamar's answer as the answer. Mostly because it's the easiest to manage, he's storing the values of each line into an array, and as long as you keep tabs on which index resides to which line, it can be easily interchanged with a line and particular value that you want. Instead of the iteration through the array for each line though in what Acamar suggested, I proposed the addition of using String.Join() instead to join each element of the array with the separator of a new line feed, which is what that line in my modified code does. It's also a bit faster than looping through, but Acamar there has a good idea if you want something that is easily manageable.

    Cheers :)


    If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
    ~ "The universe is an intelligence test." - Timothy Leary ~

    This was my last question then I will mark your proposed answer as the answer.

    If you use this process there is no need to add a line - the stub for each line already exists, and you are only making changes by appending text to the end of each line. If that's not the way it works, you will need to indicate just what you mean by 'add lines'.

    What I meant by adding lines is that some items give extra stats while others do not. Instead of showing each stat field like(which takes up space):

    |talent=

    |health=

    |toughness=

    I would like it to add the field when its chosen from the combo box.

    So if they chose Energy and typed 36 in the textbox next to it, it would put:

    |energy=36

    Or if they chose Abilities (which pops up two textboxs.. I got that to work) and typed Ice Arrow in one and Blizzard Barrage in the other,then it would put:

    |abilities=Ice Arrow, Blizzard Barrage

  • Mittwoch, 29. Februar 2012 23:52
     
      Enthält Code

    The process I described makes it possible to ignore the fact that these optional ines are 'added'.  Create your array of 'stub' items so it includes all items.     Add code to your display routine to skip items that do not yet have a value.  This might be or all of the list, or just for items beyond a certain index.  But note that trick only works if your items end in "=", which I accidentally left off most of the items in the code I provided. Also, first and last seem to be special.

        Dim lines() As String = {"{", _
                                 "|FRitem=", _
                                 "|tier=", _
                                 "|memberonly=", _
                                 "|description=", _
                                 ...
                                 "|coinshop=", _
                                 "|energy=", _
                                 "|health=", _
                                 "|}}"}
    
        Private Sub ShowText(ByVal L() As String)
            txtAllLines.Text = L(0)
            For I As Integer = 1 To L.Count - 2
                If Not L(I).EndsWith("=") Then
                    txtAllLines.Text &= L(I) & vbCrLf
                End If
            Next
            txtAllLines.Text &= L((L.Count - 1)) & vbCrLf
        End Sub

    Then treat these optional lines exactly like you treated all the others.  They won't display until they have a value.

    You might need similar code when you prepare a string to paste into the www site - it depends on whether or not you want to paste empty lines.

    If you want to stick with the conept of 'add' then that means the the number of items in the array mightchange, so a list is better than an array.  You will initialise a list differently, and some small syntax changes might be required in accessing list items.  The initialisation would be

    Dim lines as List(Of string) = New List(Of String)
    ...

      lines.add("{{FRitem")
      lines.add(
    "|tier=")
      lines.add("
    |memberonly=")

    and so on.

    Then, to add a line (to use your example):
        lines.add("|energy=" & txtEnergy.Text)

    Change the display routine so it goes to the end of the list, not to an arbitrary 18.   Note that the problem you will have (and what I was wondering about when you mentioned an add process) is how you control whether or not that line has already been added.  You may need to examine the contents of the list.  If the list contains that line, use the line index and replace the list item as per the first examples I provided.  If the list does not already contain the item, add the item to the list like I describe above. This starts to get complex, so the first option might be the best one.

  • Donnerstag, 1. März 2012 01:16
     
      Enthält Code

    The process I described makes it possible to ignore the fact that these optional ines are 'added'.  Create your array of 'stub' items so it includes all items.     Add code to your display routine to skip items that do not yet have a value.  This might be or all of the list, or just for items beyond a certain index.  But note that trick only works if your items end in "=", which I accidentally left off most of the items in the code I provided. Also, first and last seem to be special.

        Dim lines() As String = {"{", _
                                 "|FRitem=", _
                                 "|tier=", _
                                 "|memberonly=", _
                                 "|description=", _
                                 ...
                                 "|coinshop=", _
                                 "|energy=", _
                                 "|health=", _
                                 "|}}"}
    
        Private Sub ShowText(ByVal L() As String)
            txtAllLines.Text = L(0)
            For I As Integer = 1 To L.Count - 2
                If Not L(I).EndsWith("=") Then
                    txtAllLines.Text &= L(I) & vbCrLf
                End If
            Next
            txtAllLines.Text &= L((L.Count - 1)) & vbCrLf
        End Sub

    Then treat these optional lines exactly like you treated all the others.  They won't display until they have a value.

    You might need similar code when you prepare a string to paste into the www site - it depends on whether or not you want to paste empty lines.


    Last thing.... then I can finally do the rest XD... I dont know what the problem is. Sorry for bothering everybody about this...

    My |abilities= field doesnt want to work with the textboxes

    Here is a link to a picture: Picture

    Here is a link to my code: Code


    • Bearbeitet Tythesly1 Donnerstag, 1. März 2012 01:16 fixed link
    •  
  • Donnerstag, 1. März 2012 02:29
     
     

    Last thing.... then I can finally do the rest XD... I dont know what the problem is. Sorry for bothering everybody about this...

    My |abilities= field doesnt want to work with the textboxes

    Here is a link to a picture: Picture

    Here is a link to my code: Code

    Unfortunately, I don't download code from unknown sources - sorry.  Post the code from the item change event here instead.

    What event are you using?  Two procedures are relevant.  Firstly, compare the code for the text item that isn't working with the code for a text item that is working.  A difference might indicate the problem.  Secondly, insert a breakpoint at the start of the code for the event for the item that isn't working, and trace it through be stepping a line at a time.  Use the locals window and the watch window to examine vairable values at each step.  That should indicate where the error is occurring.  My guess is that you have used cut and paste to create the code and missed an item that needed to be changed.  I guess that because it's what I do very often.

    Disconnecting your display from your data so that the data update is simplified as much as possible, even if it means you have to write a small display update routine, is a very common design approach that can be very useful for tasks that initially appear quite complex.

  • Donnerstag, 1. März 2012 02:42
     
      Enthält Code

    Unfortunately, I don't download code from unknown sources - sorry.  Post the code from the item change event here instead.

    No Problem :)

        Private Sub comextra_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles comextra.SelectedIndexChanged
            If comextra.SelectedItem = "Abilities" Then
                txtextra2.Visible = True
            Else
                txtextra2.Visible = False
            End If
    
            If comextra.SelectedItem = "Abilities" Then
                itemlines(18) = "|abilities=" & txtextra1.Text & ", " & txtextra2.Text
            End If
            ShowText(itemlines)
        End Sub

    If Abilities is chosen it makes the second textbox visible. Lets say that the first textbox has Ice Arrow. And the second textbox has Blizzard Blast. The output should be this:

    |abilities=Ice Arrow, Blizzard Blast


    What event are you using?  Two procedures are relevant.  Firstly, compare the code for the text item that isn't working with the code for a text item that is working.  A difference might indicate the problem.  Secondly, insert a breakpoint at the start of the code for the event for the item that isn't working, and trace it through be stepping a line at a time.  Use the locals window and the watch window to examine vairable values at each step.  That should indicate where the error is occurring.  My guess is that you have used cut and paste to create the code and missed an item that needed to be changed.  I guess that because it's what I do very often.

    And I didn't copy and paste.... this time XD


  • Donnerstag, 1. März 2012 03:32
     
     

    When you inserted a breakpoint at the line
        If comextra.SelectedItem = "Abilities" Then
    and ran your applciation and changed the selection in the Extras combobo box, did it stop at that line?  When you stepped through one line at a time, did it get to the line
             itemlines(18) = "|abilities=" & txtextra1.Text & ", " & txtextra2.Text
    If so, what was the value of each of the text box text properties at that point, and what was the value of itemlines(18) when you stepped off that line?
    If it didn't hit the breakpoint then there is a problem in the method declaration - the only possibility I can see is that the name of the combobox control is not comextra.   If it gets to the method but doesn't get to the line to calculate a new value for itemlines(18) then you have the wrong literal value at "Abilities". If it got to that line but puts the wrong values in itemlines(18) then you are referencing the wrong text boxes for the text. If it correctly updates itemlines(18) then you need to step through the line display routine and see why it is not putting the correct text for itemlines(18) into the textbox.

  • Donnerstag, 1. März 2012 04:11
     
     

    When you inserted a breakpoint at the line
        If comextra.SelectedItem = "Abilities" Then
    and ran your applciation and changed the selection in the Extras combobo box, did it stop at that line?  When you stepped through one line at a time, did it get to the line
             itemlines(18) = "|abilities=" & txtextra1.Text & ", " & txtextra2.Text
    If so, what was the value of each of the text box text properties at that point, and what was the value of itemlines(18) when you stepped off that line?
    If it didn't hit the breakpoint then there is a problem in the method declaration - the only possibility I can see is that the name of the combobox control is not comextra.   If it gets to the method but doesn't get to the line to calculate a new value for itemlines(18) then you have the wrong literal value at "Abilities". If it got to that line but puts the wrong values in itemlines(18) then you are referencing the wrong text boxes for the text. If it correctly updates itemlines(18) then you need to step through the line display routine and see why it is not putting the correct text for itemlines(18) into the textbox.

    I cant figure it out.... Also Its 11:00 pm and I cant think straight lol... Ill try again tomorrow in the afternoon. But I know that you can probably figure it out. Good Night lol.

    I know you said you dont download from outside sources but in case this changes your mind:

    1. Link to picture of antivirus scan (using avg) on zip file: http://www.flickr.com/photos/75584896@N03/6942849783/

    2. Antivirus scanning policy of the file sharing website I'm using: http://www.4shared.com/features/anti-virus/index.jsp

    3. Link to the zip file containing the published program and the code/design files: http://www.4shared.com/zip/LyG4Pm34/My_ZAM_App_with_Project_Code_a.html        

  • Donnerstag, 1. März 2012 05:37
    Moderator
     
      Enthält Code

    Hi Tythesly1,

    First I want to say that while you did a good job describing the issue in your post, the thread title could be improved a little.  We tend to discourage verbage like "help me asap" because it is not useful to others when searching for answers.  A descriptive title, even if you're not quite sure how to word it, is better than "please help me".  In this case you might use something like "...need help inserting variables into a string".  Its not a big deal, so please take it as more a "for future referece" kind of thing.

    Second, I wanted to show you an alternate solution using an object model of your data.  This isn't to say that there is anything wrong with the direction you've been given thus far, this is just an alternate solution offered as something you might learn from.

    To use this sample, just start a new Windows Forms Application project and paste this code over the default Form1 code.  Please note that I haven't actually played the game very much so you'll have to adjust the enumerations as needed.  You may also want additional helper methods for the output as I'm not entirely sure what the valid values are for the web data.

    Public Class Form1
        Friend WithEvents LayoutPanel As New FlowLayoutPanel With {.AutoScroll = True, .Dock = DockStyle.Fill}
        Friend WithEvents SaveButton As New Button With {.Dock = DockStyle.Bottom, .Text = "Save"}
    
        Private _EditItem As New FRItem
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            For Each info As System.Reflection.PropertyInfo In GetType(FRItem).GetProperties
                Dim titleLabel As New Label With {.AutoSize = True, .Text = info.Name}
                Dim editControl As Control = Nothing
                If info.PropertyType.IsEnum Then
                    Dim editComboBox As New ComboBox With {.DropDownStyle = ComboBoxStyle.DropDownList}
                    editComboBox.Items.AddRange(info.PropertyType.GetEnumNames)
                    editComboBox.DataBindings.Add("SelectedItem", _EditItem, info.Name, True)
                    editComboBox.SelectedIndex = 0
                    editControl = editComboBox
                ElseIf info.PropertyType Is GetType(Boolean) Then
                    Dim editYesButton As New RadioButton With {.AutoSize = True, .Text = "Yes", .Top = 1}
                    Dim editNoButton As New RadioButton With {.AutoSize = True, .Text = "No", .Top = 1}
                    Dim editPanel As New Panel
                    editYesButton.DataBindings.Add("Checked", _EditItem, info.Name)
                    editPanel.Controls.Add(editYesButton)
                    editPanel.Controls.Add(editNoButton)
                    editNoButton.Left = editYesButton.Width
                    editPanel.Width = editYesButton.Width + editNoButton.Width
                    editPanel.Height = editYesButton.Height
                    editControl = editPanel
                ElseIf info.PropertyType Is GetType(Integer) Then
                    Dim editUpDown As New NumericUpDown
                    editUpDown.DataBindings.Add("Value", _EditItem, info.Name)
                    editControl = editUpDown
                Else
                    Dim editTextBox As New TextBox
                    editTextBox.DataBindings.Add("Text", _EditItem, info.Name)
                    editControl = editTextBox
                End If
                LayoutPanel.Controls.Add(titleLabel)
                LayoutPanel.Controls.Add(editControl)
                LayoutPanel.SetFlowBreak(editControl, True)
            Next
            Controls.Add(LayoutPanel)
            Controls.Add(SaveButton)
        End Sub
    
        Private Sub SaveButton_Click(sender As Object, e As System.EventArgs) Handles SaveButton.Click
            Clipboard.SetText(_EditItem.ToString)
            My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Exclamation)
        End Sub
    End Class
    
    Public Class FRItem
        Public Shared ReadOnly WebFormat As String = "FR Item|tier={0}|membersonly={1}|description={2}|spawn={3}|sc={4}|power={5}|gender={6}|race={7}|job={8}|minlevel={9}|minrank={10}|slot={11}|notrade={12}|nosell={13}|unlimited={14}|coinshop={15}|"
    
        Public Property Tier As ItemTier
        Public Property MemberOnly As Boolean
        Public Property Description As String = String.Empty
        Public Property Spawn As String = String.Empty
        Public Property StationCash As Integer
        Public Property Power As ItemPower
        Public Property Gender As PlayerGender
        Public Property Race As PlayerRace
        Public Property Job As PlayerJob
        Public Property MinLevel As Integer
        Public Property MinRank As Integer
        Public Property Slot As ItemSlot
        Public Property NoTrade As Boolean
        Public Property NoSell As Boolean
        Public Property Unlimited As Boolean
        Public Property CoinShop As ItemCoinShop
    
        Public Overrides Function ToString() As String
            Return String.Concat("{{",
                                 String.Format(WebFormat, IsNone(Tier), YesNo(MemberOnly), Description, Spawn, StationCash, CInt(Power),
                                               IsNone(Gender), IsNone(Race), IsNone(Job), MinLevel, MinRank, IsNone(Slot), YesNo(NoTrade),
                                               YesNo(NoSell), YesNo(Unlimited), IsNone(CoinShop)),
                                 "}}")
        End Function
    
        Private Function IsNone(value As [Enum]) As String
            Dim valueName As String = value.ToString
            If valueName = "None" Then Return String.Empty
            Return valueName
        End Function
    
        Private Function YesNo(value As Boolean) As String
            If value Then Return "y"
            Return "n"
        End Function
    End Class
    
    Public Enum ItemTier
        None
        White
        Green
        Blue
        Purple
        Orange
        Gold
    End Enum
    
    Public Enum ItemPower
        None = 0
        One = 1
        Two = 2
        Three = 3
        Four = 4
        Five = 5
    End Enum
    
    Public Enum PlayerGender
        None
        Guy
        Gal
    End Enum
    
    Public Enum PlayerRace
        None
        Human
        Pixie
    End Enum
    
    Public Enum PlayerJob
        None
        Warrior
        Wizard
        Brawler
        Archer
        Ninja
        Medic
        Miner
        Blacksmith
        Chef
        Fisherman
        Postman
        SoccerStar
        KartDriver
        CardDuelist
    End Enum
    
    Public Enum ItemSlot
        None
        Head
        Chest
        Hands
        Legs
        Feet
    End Enum
    
    <Flags()>
    Public Enum ItemCoinShop
        None = 0
        CoinShop = 1
        Marketplace = 2
        Both = 3
    End Enum


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

  • Donnerstag, 1. März 2012 20:42
     
     
    ALRIGHT!! I got the combo box to work the way I want. It now shows the selected text ... but for some reason any text I put in the text boxes next to it dont show up in the right window.
  • Donnerstag, 1. März 2012 20:43
     
     
    Thanks for letting me know about the title, and thanks for the alternate solution. But I'm going to stick with what I've learned from here. :D
  • Donnerstag, 1. März 2012 20:45
     
     

    What was the result from inserting the breakpoint and single stepping the code?

    If you change the text in the text boxes after selecting the item in the combobox, then you need the code that's in the combobox index changed event handler to be also inserted into the text changed event handlers for the text boxes.

  • Donnerstag, 1. März 2012 21:02
     
     

    You did it!!! Thats what was wrong! Thank you everybody who helped me out!!!!!!!!!!!!!!!


    • Bearbeitet Tythesly1 Donnerstag, 1. März 2012 21:46 DONE
    •  
  • Donnerstag, 1. März 2012 23:07
     
     

    You did it!!! Thats what was wrong! Thank you everybody who helped me out!!!!!!!!!!!!!!!

    I hope that before too long you will take a look at the object-based solution posted at the end of this thread.  You will see that it is a further development of some of the design principles that have been implemented in the solution you currently have.

  • Donnerstag, 1. März 2012 23:28
     
     

    You did it!!! Thats what was wrong! Thank you everybody who helped me out!!!!!!!!!!!!!!!

    I hope that before too long you will take a look at the object-based solution posted at the end of this thread.  You will see that it is a further development of some of the design principles that have been implemented in the solution you currently have.

    I saved everything as a word document :D