Convert a console Application to a Windows Forms Application VB.NET

Posted on 2009-04-22
Last Modified: 2013-11-26
I am working with a sample application that was made as a console application and I dont know much about console apps.  I want to convert to a windows forms application but I'm not sure how to rewrite it.

See the sample code.  How would I covert that so it will display in a text box instead of a console window?
If (Not ratedPackage.PackageRateDetail Is Nothing) Then

                                    Console.WriteLine("Package {0}", p)

                                    Console.WriteLine("Billing weight {0} {1}", ratedPackage.PackageRateDetail.BillingWeight.Value, ratedPackage.PackageRateDetail.BillingWeight.Units)

                                    Console.WriteLine("   Base charge {0} {1}", ratedPackage.PackageRateDetail.BaseCharge.Amount, ratedPackage.PackageRateDetail.BaseCharge.Currency)

                                    For Each surcharge As Surcharge In ratedPackage.PackageRateDetail.Surcharges

                                        Console.WriteLine("{0} surcharge {1} {2}", surcharge.SurchargeType.ToString(), surcharge.Amount.Amount, surcharge.Amount.Currency)


                                    Console.WriteLine("    Net charge {0} {1}", ratedPackage.PackageRateDetail.NetCharge.Amount, ratedPackage.PackageRateDetail.NetCharge.Currency)

                                    p = p + 1

                                End If

Open in new window

Question by:handyjay
    LVL 10

    Expert Comment

    just put a richtextbox on a form, clear its content...

    ...and add all your lines like this:
            Me.RichTextBox1.AppendText("My stuff " & vbCrLf)
    LVL 10

    Expert Comment

    The only point i'm not sure is about your {0} and {1}.  I don't remember what they do... but if its for formatting, then you can do this:

    Me.RichTextBox1.AppendText("Billing weight " & _
                                                     ratedPackage.PackageRateDetail.BillingWeight.Value.ToString() & " " & _

    Author Comment

    The problem I am having was not knowing what {0} and {1} means.  I am trying to convert someone elses console app.  It seems that they are place holders for the following two values so your answer is probably correct.  Anyone know what {0} and {1} mean??
    LVL 10

    Accepted Solution

    i think it's parameters.  If you have 3 parameters you would have {0} {1} {2}.

    But test what i said, you will see, it will work.   The result will be displayed in a RichTextBox (just like a VB6 app would do).

    But if you want the complete code, here it is:
    If (Not ratedPackage.PackageRateDetail Is Nothing) Then
         RichTextBox1.AppendText("Package " & p & vbCrLf)
         with ratedPackage.PackageRetail
              RichTextBox1.AppendText("Billing weight " & _
                  .BillingWeight.ToString & " " & _
                  .BillingWeight.Units.ToString & vbCrLf ) 
              RichTextBox1.AppendText("    Base Charge " & _
                  .BaseCharge.Amount.ToString & " " & _ 
                  .BaseCharge.Currency.ToString & vbCrLf)
             For Each surcharge As Surcharge In .Surcharges
                 RichTextBox1.AppendText(" " & _
                     surcharge.SurchargeType.ToString() & " " & _
                     "surcharge " & _
                     surcharge.Amount.Amount.ToString & " " & _
                     surcharge.Amount.Currency.ToString & " " & vbCrLf)
              RichTextBox1.AppendText("    Net Charge " & _
                  .NetCharge.Amount.ToString & " " & _ 
                  .NetCharge.Currency.ToString & vbCrLf)
         end with
         p = p + 1
    End If

    Open in new window


    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now