# Visual Basic > Visual Basic .NET > VS 2019 test

## vbmb2020

Hello Guys,

I was just wondering if anyone can help me please?.

I have a label on my form called lblName and was wondering in the code below where it says Smiley's Snooker how do i replace this with the text that's on the lblName so i dont need to change this code all the time?



```
 Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

        Dim Index, NumberOfRecords, RecordNumber, Table As Short
        Dim Minute, Hour As Short
        Dim X, Y As Short
        Dim FontHeight As Short
        Dim OneFinishedGame As GameFinishedType
        Dim GamesForOneTable As Short
        Dim TimeForOneTable As Short
        Dim IncomeForOneTable As Decimal
        Dim TotalIncome As Decimal
        Dim MinutesPlayed As Short
        Dim MyFont As New Font("Courier New", 11, FontStyle.Bold)
        Dim MyTitleFont As New Font("Courier New", 13, FontStyle.Bold Or FontStyle.Underline)
        Dim Myformat As String = "{0, -15}{1, -15}{2, -25}{3, -15}"
        Dim LineToPrint As String
        X = 50
        Y = 50
        FontHeight = MyFont.GetHeight(e.Graphics)
        e.Graphics.DrawString("Smiley's Snooker.  Table use for " & Now, MyTitleFont, Brushes.Black, X, Y)
        Call printblanklines(X, Y, FontHeight, MyFont, e)
        LineToPrint = String.Format(Myformat, "Total No,", "No. Games", "Time", "Income")
        e.Graphics.DrawString(LineToPrint, MyFont, Brushes.Black, X, Y)
        Call printblanklines(X, Y, FontHeight, MyFont, e)

        For Table = 1 To MaxTables

            FileOpen(1, "FinishedGames.dat", OpenMode.Random, , , Len(OneFinishedGame))
            NumberOfRecords = LOF(1) / Len(OneFinishedGame)
            GamesForOneTable = 0
            TimeForOneTable = 0
            IncomeForOneTable = 0
            For Index = 1 To NumberOfRecords
                FileGet(1, OneFinishedGame)
                If OneFinishedGame.TableID = Table Then
                    GamesForOneTable = GamesForOneTable + 1
                    MinutesPlayed = NumberOfMinutes(OneFinishedGame.FinishTime, OneFinishedGame.StartTime)
                    TimeForOneTable = TimeForOneTable + MinutesPlayed
                    IncomeForOneTable = IncomeForOneTable = OneFinishedGame.Cost
                End If
            Next Index

            TotalIncome = TotalIncome = IncomeForOneTable

            If TimeForOneTable >= 60 Then
                Hour = TimeForOneTable \ 60
            Else
                Hour = 0
            End If

            Minute = TimeForOneTable Mod 60
            LineToPrint = String.Format(Myformat, Table, GamesForOneTable, Hour & " hrs " & Minute & " Mins", Format(IncomeForOneTable, "Currency"))
            e.Graphics.DrawString(LineToPrint, MyFont, Brushes.Black, X, Y)
            Y = Y + FontHeight
            FileClose(1)

        Next Table

        Call printblanklines(X, Y, FontHeight, MyFont, e)
        LineToPrint = "Total Income: " & Format(TotalIncome, "Currency")
        e.Graphics.DrawString(LineToPrint, MyFont, Brushes.Black, 425, Y)

        Call DeleteFinishedGamesFile()

    End Sub
```

Thanks so much for reading my post and any help is much appreciated..

----------


## Shaggy Hiker

What's with the meaningless title?

All you need for the question is to replace:


```
e.Graphics.DrawString("Smiley's Snooker.  Table use for " & Now, MyTitleFont, Brushes.Black, X, Y)
```

with



```
e.Graphics.DrawString( lblName.Text & " Table use for " & Now, MyTitleFont, Brushes.Black, X, Y)
```

----------


## vbmb2020

Thank you so much that helped me alot 

how do i do it as if i was getting the text from another forms label like below?



```
e.Graphics.DrawString(frmMain.lblHallName.Text & " List of current members on " & Format(Today, "Long Date"), MyTitleFont, Brushes.Black, X, Y)
```

----------


## Shaggy Hiker

You could do it exactly as you have it written, so long as a set of assumption is true. For one thing, frmMain would have to be the instance of the form that has the label on it. Considering you used the name 'frmMain', that is more likely to be true than not, but the fact that you asked the question suggests that perhaps it is not true.

Ultimately, it is probably not the best way to do things, simply because it ties the instances of the forms together and ties the functioning of the current form to the very existence of some other instance of a form with a name of frmMain. That can cause all kinds of problems. Better would be to put a property on the current form, and set that property with the value you want to show.

As it stands, 'frmMain' sounds like a type name. You'd have to create an instance of that type to be able to use it, something like:


```
Dim myForm As New frmMain
```

Alternatively, frmMain could be the instance:


```
Dim frmMain As New SomeTypeOfFormHere
```

Even worse, with default instances of forms, frmMain could be both an instance AND a type:


```
Dim frmMain As New frmMain
```

That would trip people up an awful lot, though it seems like we haven't talked about that in years, so perhaps it is fading out as an issue. It's still possible, though. Especially if frmMain is your startup object, then you are almost certainly getting a default instance, in which case you will have a variable called frmMain which is of type frmMain. That causes all kinds of confusion, as people mistake the instance for the type and think they are the same thing, since they have the same name.

In this case, I'm not sure why you are asking the question. It might be that the code you wrote works already, but it could also be that it doesn't work, in which case it is likely due to confusion over the default instance. Either way, you are better off putting a property on the form. Internally, the line of code would only use whatever that property was set to, and would know nothing at all about anything outside of the form. The code that created/showed the form would then be responsible for setting the property to whatever you want it to be.

----------

