dcsimg
Results 1 to 9 of 9

Thread: [RESOLVED] Need to write stringbuilder data as test during debugging.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2019
    Posts
    67

    Resolved [RESOLVED] Need to write stringbuilder data as test during debugging.

    Originally written in VB2010, now using VS2019.
    I need a way of looking at what data is being generated and accumulated in a segment of code. Because they are calls to functions and arrays, setting a breakpoint a hovering the cursor over the statements does not work. Note that the calls to functions, etc., all worked before my attempt at converting from string concatenation to Stringbuilder worked.
    I have tried inserting a MsgBox and writing it to a text box (Form3.TestBox2.Text = paddingBuilder.ToString) but neither work.

    Code:
    Dim paddingBuilder As New StringBuilder
            For Each InToCode In AssignedNumArray 'For IntCount = 1 To NumberOf
                'Select Case AssignedNumArray(IntCount)
                Select Case InToCode
                    Case "60"    '  (space)
                        StrPadding = AddPad()         
                        StrPadding(7) = GetEven()    
                        paddingBuilder.Append(StrPadding) 
                        StrPadding = AddPad()
                        StrPadding(7) = GetOdd()            
                        paddingBuilder.Append(StrPadding)
                        StrPadding = AddPad()
                        StrPadding(7) = GetOdd()
                        paddingBuilder.Append(StrPadding)
                        StrPadding = AddPad()
                        StrPadding(7) = GetOdd()
                        paddingBuilder.Append(StrPadding)
                        StrPadding = AddPad()
                        StrPadding(7) = GetOdd()
                        paddingBuilder.Append(StrPadding)
    Last edited by Bushranger; Jan 19th, 2020 at 06:43 AM.

  2. #2
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,282

    Re: Need to write stringbuilder data as test during debugging.

    If it were me, I'd put a break point on the line Select Case InToCode and run your code. When execution stops on that line, I'd step through the code and examine the values by hovering the mouse over the variable names.

    When debugging from a break point, you can step into, step over and step out of your code. You can use the function keys to do this, or select the appropriate entry from the DEBUG menu item from the IDE's main menu (you'll see the function key mapping there too; for me it's F8, Shift F8, and Control Shift F8 respectively, although F10 also maps to Step Over). Step Over is probably most useful for you here.

    You could also use one of the debugging windows such as a Watch Window or the Locals Window instead of, or as well as using mouse hovering. Up to you. Might be an idea to stop coding for a while and research what debugging tools/methods are available to you.


    Note that paddingBuilder.Append(StrPadding) isn't going to work. StringBuilder.Append appends the string representation of an object to the StringBuilder value. StrPadding is an Integer Array. The string representation of an Integer Array is System.Int32[]. You need to concat the values of the array elements to make a String and append that to the StringBuilder. I showed you how to do that efficiently in an earlier thread: String.Concat(StrPadding)


    Edit: remember (as Wes mentioned in an earlier thread) that when using break points and stepping through code, the line that is highlighted hasn't been executed yet, so any variable that is assigned a value on that line will not be updated until you step past that line.
    Last edited by Inferrd; Jan 19th, 2020 at 07:41 AM.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2019
    Posts
    67

    Re: Need to write stringbuilder data as test during debugging.

    Quote Originally Posted by Inferrd View Post
    Note that paddingBuilder.Append(StrPadding) isn't going to work. StringBuilder.Append appends the string representation of an object to the StringBuilder value. StrPadding is an Integer Array. The string representation of an Integer Array is System.Int32[]. You need to concat the values of the array elements to make a String and append that to the StringBuilder. I showed you how to do that efficiently in an earlier thread: String.Concat(StrPadding)
    Someone else game me this:
    paddingBuilder.Append(StrPadding)
    Someone gave me this:
    paddingBuilder.Append(String.Concat)StrPadding)).
    Do you literally mean: "String.Concat(StrPadding)"? Or, is there some preface that refers to "paddingBuilder.Append"?

  4. #4
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,282

    Re: Need to write stringbuilder data as test during debugging.

    Quote Originally Posted by Bushranger View Post
    Do you literally mean: "String.Concat(StrPadding)"? Or, is there some preface that refers to "paddingBuilder.Append"?
    StrPadding is an array. It doesn't make sense to append an array to a StringBuilder. What you want to do is make a String from the contents of the array and append that String to the StringBuilder.

    So you'd have something like (typed freehand):
    Code:
    Dim enctyptedCharString As String = String.Concat(StrPadding)
    paddingBuilder.Append(encryptedCharString)
    Or you can shorten that to:
    Code:
    paddingBuilder.Append(String.Concat(StrPadding))
    Whichever you find is easier to read. :-)

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2019
    Posts
    67

    Re: Need to write stringbuilder data as test during debugging.

    I appreciate the help you have given to me...I am really struggling with this.

  6. #6
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,911

    Re: Need to write stringbuilder data as test during debugging.

    It still looks like you are declaring your StringBuilder instance local to the sub you are calling.
    Before you were concatenating strings into a textbox, which would persist the string between calls to the sub that appended to the textbox.

    You need to declare the StringBuilder instance outside the sub that your are calling to append to the stringbuilder so that its data will be persisted as well.
    By declaring it local to the sub, you are using a new instance (i.e. no strings in the stringbuilder) each time you try to append new strings to it. I believe Inferrd gave you an example in another thread that show that being done.

    I admit I'm wondering why you have to rewrite anything, being that if the code was written in VB2010, it should load and run in VS 2019 without any modification.

    The first code you showed in your first post quite a while back looked very strongly like VB6 code, so I could see having to rewrite the code to get it to work in VS 2019.
    I suppose if you're just trying to take the opportunity of improving the code written in VB2010 to make it more .Net oriented vs Legacy Basic code, then that is a reasonable thing, but that is a justification of its own, and doesn't really matter if your going from 2010 to 2019 or 2012 to 2019, or 2013 to 2019, etc...

    All the versions between 2010 and 2019 should run in 2019 without having to be modified. Modifiying the code to make it better is an independent justification, regardless of the fact that it was written in 2010.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Dec 2019
    Posts
    67

    Re: Need to write stringbuilder data as test during debugging.

    I admit I'm wondering why you have to rewrite anything, being that if the code was written in VB2010, it should load and run in VS 2019 without any modification.
    Originally the code was written using many string concatenations and the program ran so slow when encrypting that it was virtually useless. One of the "speedups" that was suggested was that I change my code from many, many string concatenations, to using a StringBuilder instead. Today, using Inferrd's suggestions, I was successful...the code/program runs very fast now.

  8. #8
    Fanatic Member
    Join Date
    Nov 2017
    Posts
    1,003

    Re: [RESOLVED] Need to write stringbuilder data as test during debugging.


  9. #9

    Thread Starter
    Lively Member
    Join Date
    Dec 2019
    Posts
    67

    Re: Need to write stringbuilder data as test during debugging.

    Quote Originally Posted by Inferrd View Post
    StrPadding is an array. It doesn't make sense to append an array to a StringBuilder. What you want to do is make a String from the contents of the array and append that String to the StringBuilder.

    So you'd have something like (typed freehand):
    Code:
    Dim enctyptedCharString As String = String.Concat(StrPadding)
    paddingBuilder.Append(encryptedCharString)
    Or you can shorten that to:
    Code:
    paddingBuilder.Append(String.Concat(StrPadding))
    Whichever you find is easier to read. :-)
    Success! Bypassed the Function "ToFile" completely, appended all data using stringbuilder, internally...then wrote it to the Textbox in one fell swoop. Program runs way, way faster than when string concatenation was used. Thank you Inferrd!
    Last edited by Bushranger; Jan 19th, 2020 at 11:22 PM.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width