12 Replies - 695 Views - Last Post: 11 October 2012 - 01:45 PM Rate Topic: -----

#1 LordAizen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 11-October 12

Need newline in text box for a do until loop

Posted 11 October 2012 - 01:02 PM

I'm trying to create a simple program for my computing class but i'm having a lot of trouble getting this to work after putting a lot of time into looking into other peoples problems which are similar to my own I haven't found a solution.
 Lbl_output1.Text = Result1
        Lbl_ouput2.Text = Result2

        Dim intcounter As Integer = 1

        If Cbx_Squared.CheckState = CheckState.Checked Then
            Do Until intcounter = 11

                Txt_ouput.Text = (intcounter * intcounter)
                Txt_ouput.Text += Environment.NewLine

                intcounter = intcounter + 1

            Loop
        End If



I'm trying to get it so that each time the loop resolves it puts the value onto a new line of the text box, the output simply being the squared number of 1-10 on different lines. I have tried + vbcrlf and + environment.newline after the intcounter * intcounter, getting the error cannot convert from string to double. This currently has no errors but only outputs 100 on the first line.
Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: Need newline in text box for a do until loop

#2 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 227
  • View blog
  • Posts: 746
  • Joined: 19-October 11

Re: Need newline in text box for a do until loop

Posted 11 October 2012 - 01:10 PM

In your Do Until ... Loop, you are now doing:
  • assign to .Text property of Txt_ouput the value of current intcounter value on the power of 2 ( 2 * 2 = 2 ^2 as is 3 * 3 = 3^2)
  • then add newline to the same .Text property
  • you increment intcounter by one
  • and you loop


What you should be doing is:
add to .Text property of Txt_output the value...
... and everything else as before.
Was This Post Helpful? 1
  • +
  • -

#3 LordAizen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 11-October 12

Re: Need newline in text box for a do until loop

Posted 11 October 2012 - 01:13 PM

Sorry i'm a novice at VB we've just started the course how does one add to a text box?
Thank you for your input already. =]
Was This Post Helpful? 0
  • +
  • -

#4 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 227
  • View blog
  • Posts: 746
  • Joined: 19-October 11

Re: Need newline in text box for a do until loop

Posted 11 October 2012 - 01:14 PM

As you add newline to what you already added in your code at line 10.

This post has been edited by lucky3: 11 October 2012 - 01:15 PM

Was This Post Helpful? 1
  • +
  • -

#5 LordAizen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 11-October 12

Re: Need newline in text box for a do until loop

Posted 11 October 2012 - 01:16 PM

If you mean by using += then I just tried that I got the cannot convert from string to double error again.

I'm sorry thank you again.
Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is online

  • This space intentionally left blank
  • member icon

Reputation: 1386
  • View blog
  • Posts: 4,464
  • Joined: 25-September 09

Re: Need newline in text box for a do until loop

Posted 11 October 2012 - 01:23 PM

The & is used to concatenate string. Sometimes, + can try to perform calculation.
Was This Post Helpful? 1
  • +
  • -

#7 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 227
  • View blog
  • Posts: 746
  • Joined: 19-October 11

Re: Need newline in text box for a do until loop

Posted 11 October 2012 - 01:24 PM

So you have Option Strict On set by default, and that is the reason. Keep it that way, you'll learn more. What you need to do, is add .ToString() behind (intcounter * intcounter), so it looks like: (intcounter * intcounter).ToString(). And instead of +=, use &= when dealing with strings. With Option Strict On, there should be no trouble using +=, but if you ever decide to switch it off, you could find yourself doing mathematical addition, instead of concatenating text.
Was This Post Helpful? 2
  • +
  • -

#8 LordAizen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 11-October 12

Re: Need newline in text box for a do until loop

Posted 11 October 2012 - 01:25 PM

Most thanks kind sir it worked. Many hours spent are now to an end thanks so much.
you don't know how happy I am.
Was This Post Helpful? 0
  • +
  • -

#9 DimitriV  Icon User is offline

  • Don't try to save yourself… the circle is complete
  • member icon

Reputation: 544
  • View blog
  • Posts: 2,632
  • Joined: 24-July 11

Re: Need newline in text box for a do until loop

Posted 11 October 2012 - 01:26 PM

You could use &=, you could add a line by saying: TextBox1.Text &= Chr(13).
Wow. Beaten to it.

This post has been edited by DimitriV: 11 October 2012 - 01:26 PM

Was This Post Helpful? 1
  • +
  • -

#10 LordAizen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 11-October 12

Re: Need newline in text box for a do until loop

Posted 11 October 2012 - 01:26 PM

Thank you both for your help really.
Was This Post Helpful? 0
  • +
  • -

#11 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 227
  • View blog
  • Posts: 746
  • Joined: 19-October 11

Re: Need newline in text box for a do until loop

Posted 11 October 2012 - 01:40 PM

DimitriV :) perhaps Txt_ouput.Text &= ChrW(13) & ChrW(10), but not to confuse OP: vbNewLine is most used for adding new line in VB.NET.
Was This Post Helpful? 1
  • +
  • -

#12 CharlieMay  Icon User is online

  • This space intentionally left blank
  • member icon

Reputation: 1386
  • View blog
  • Posts: 4,464
  • Joined: 25-September 09

Re: Need newline in text box for a do until loop

Posted 11 October 2012 - 01:44 PM

Environment.Newline for when you don't want to use the VisualBasic namespace too.
Was This Post Helpful? 1
  • +
  • -

#13 AdamSpeight2008  Icon User is online

  • MrCupOfT
  • member icon


Reputation: 1954
  • View blog
  • Posts: 8,692
  • Joined: 29-May 08

Re: Need newline in text box for a do until loop

Posted 11 October 2012 - 01:45 PM

Environment.NewLine is the best since a newline is culture dependent.

This post has been edited by AdamSpeight2008: 11 October 2012 - 03:33 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1