[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2009-04-22
4
Medium Priority
?
624 Views
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)
                                    Next
                                    Console.WriteLine("    Net charge {0} {1}", ratedPackage.PackageRateDetail.NetCharge.Amount, ratedPackage.PackageRateDetail.NetCharge.Currency)
                                    p = p + 1
                                End If

Open in new window

0
Comment
Question by:handyjay
  • 3
4 Comments
 
LVL 10

Expert Comment

by:Christian de Bellefeuille
ID: 24209866
just put a richtextbox on a form, clear its content...
        Me.RichTextBox1.Clear()

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

Expert Comment

by:Christian de Bellefeuille
ID: 24209884
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() & " " & _
                                                 ratedPackage.PackageRateDetail.BillingWeight.Units.ToString())
0
 

Author Comment

by:handyjay
ID: 24210742
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??
0
 
LVL 10

Accepted Solution

by:
Christian de Bellefeuille earned 2000 total points
ID: 24216978
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.Clear
     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)
         Next
 
          RichTextBox1.AppendText("    Net Charge " & _
              .NetCharge.Amount.ToString & " " & _ 
              .NetCharge.Currency.ToString & vbCrLf)
 
     end with
     p = p + 1
End If

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

834 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