Home All Groups Group Topic Archive Search About

Mixing VB variables with standard text to output text file

Author
30 Mar 2005 7:49 PM
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

Author
30 Mar 2005 8:02 PM
Crouchie1998
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?
Author
30 Mar 2005 8:07 PM
Tom Shelton
In article <ApD2e.25175$ME3.25***@newsfe1-gui.ntli.net>, Scott wrote:

Show quoteHide quote
> 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 :)

--
Tom Shelton [MVP]
Author
30 Mar 2005 8:55 PM
Crouchie1998
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
Author
30 Mar 2005 9:16 PM
Scott
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
Author
31 Mar 2005 6:18 AM
Tom Shelton
In article <IGE2e.25191$ME3***@newsfe1-gui.ntli.net>, Scott wrote:
Show quoteHide quote
> 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)


--
Tom Shelton [MVP]
Author
31 Mar 2005 6:22 AM
Cor Ligthert
Hi Tom.

Of course.

:-)

Cor

Show quoteHide quote
>
> 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."
>
Author
31 Mar 2005 6:10 AM
Tom Shelton
In article <u7QbAsWNFHA.1***@tk2msftngp13.phx.gbl>, Crouchie1998 wrote:
> 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

--
Tom Shelton [MVP]
Author
30 Mar 2005 9:27 PM
Cor Ligthert
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