Mixing VB variables with standard text to output text file

  • Thread starter Thread starter Scott
  • Start date Start date
S

Scott

I wish to create a text document (to the users desktop on any machine) which outputs to a standard text file with information obtained from there use of my program... Some of the text will be fixed and some will be variables generated in VB.net. For example...

You have chosen a SINGLE TRIP, which is within EUROPE and is for FAMILY and last for 27 days. The trips starts from 24/04/05 until 30/04/05 and you chose to use more than 17 days of winter sports. The total price for your trip £155.00.

The BOLD CAPS mean they are variables from VB.net.

Any help would be appreciated!!!

Scott
 
Where's the code from your program?

Will the users have a text box to enter the length of time & datetimepickers to select the start/end dates?

Will the program be run locally or from the server?
 
I wish to create a text document (to the users desktop on any machine) =
which outputs to a standard text file with information obtained from =
there use of my program... Some of the text will be fixed and some will =
be variables generated in VB.net. For example...

You have chosen a SINGLE TRIP, which is within EUROPE and is for FAMILY =
and last for 27 days. The trips starts from 24/04/05 until 30/04/05 and =
you chose to use more than 17 days of winter sports. The total price =
for your trip =A3155.00.

The BOLD CAPS mean they are variables from VB.net.

Any help would be appreciated!!!

Scott

Const MESSAGE_TEMPLATE As String = "You have chosen a {0}, which is
within {1} and is for {2} and lasts for 27 days. The trip starts from
24/04/05 until 30/04/05 and you chose to use more than 17 days of winter
sports. The total price for your trip is $155.00"


Dim Message As String = String.Fromat (MESSAGE_TEMPLATE, tripVariable,
placeVariable, familyVariable)

Anyway, something like that :) I have a hard time reading you message
because it was in html format - and I only use a text only reader :)
 
What is the price per day?

Tom,

That format you supplied isn't static text because the variables change,
therefore, you cannot declare it as constant
 
Hopefully that will read better...

I need to output to a new file that must be created on the desktop... a lot
of the code is pre-fixed with the variables filling in the blanks... The
most important thing is saving to the desktop on any particular machine,
within the network...

Here is the original text I wrote...

I wish to create a text document (to the users desktop on any machine) which
outputs to a standard text file with information obtained from there use of
my program... Some of the text will be fixed and some will be variables
generated in VB.net. For example...

You have chosen a SINGLE TRIP, which is within EUROPE and is for FAMILY and
last for 27 days. The trips starts from 24/04/05 until 30/04/05 and you
chose to use more than 17 days of winter sports. The total price for your
trip £155.00.

The BOLD CAPS mean they are variables from VB.net.

Any help would be appreciated!!!

Scott
 
Scot,

You mean something as this

"You have chosen a @1, which is within @2 is for @3............"

String1 = String1.Replace("@1","Single Trip") 'probably a datafield.
String1 = String1.Replace("@2 etc)

This is not a quick method however for this small string not slow too, very
easy and good documentative in my opinion.

I hope this helps,

Cor
 
What is the price per day?

Tom,

That format you supplied isn't static text because the variables change,
therefore, you cannot declare it as constant

Yes you can... I do this all the time. It is a template to pass to
string.format.

Try it:
Option Strict On
Option Explicit On

Public Class Example
Private Const FORMAT_TEMPLATE As String = "Hi {0}"

Public Shared Sub Main ()
Dim Message As String = String.Format (FORMAT_TEMPLATE, "Crouchie")

Console.WriteLine (Message)
End Sub
End Class
 
Hopefully that will read better...

I need to output to a new file that must be created on the desktop... a lot
of the code is pre-fixed with the variables filling in the blanks... The
most important thing is saving to the desktop on any particular machine,
within the network...

Here is the original text I wrote...

I wish to create a text document (to the users desktop on any machine) which
outputs to a standard text file with information obtained from there use of
my program... Some of the text will be fixed and some will be variables
generated in VB.net. For example...

You have chosen a SINGLE TRIP, which is within EUROPE and is for FAMILY and
last for 27 days. The trips starts from 24/04/05 until 30/04/05 and you
chose to use more than 17 days of winter sports. The total price for your
trip £155.00.

The BOLD CAPS mean they are variables from VB.net.

Any help would be appreciated!!!

Scott

See my original reply...

Option Strict On
Option Explicit On

Imports System

Public Class Example
Private Const String MESSAGE_TEMPLATE = _
"You have chosen a {0}, which is within {1} and is for {2} and last for 27 days. The trips starts from 24/04/05 until 30/04/05 and you chose to use more than 17 days of winter sports. The total price for your trip £155.00."

Public Shared Sub Main ()

Console.WriteLine _
(MESSAGE_TEMPLATE, "SINGLE TRIP", "EUROPE", "FAMILY")
End Sub
End Class

You could also format it to a string using String.Format...
Dim Message As String = String.Format _
(MESSAGE_TEMPLATE, "SINGLE TRIP", "EUROPE", "FAMILY")
Console.WriteLine (Message)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top