Husna5207
Husna5207

Reputation: 459

How to declare a path of file in vb.net?

I'm going to do something like this,

If txt1.Text = "A" And txt2.Text = "B" Then
"path of my file which name is = c:/A.B"
End If

If txt1.Text = "C" And txt2.Text = "D" Then
"path of my file which name is = c:/C.D"
End If

How I'm going to do something like this ? I'm using vb.net

Upvotes: 0

Views: 1972

Answers (3)

Harsh
Harsh

Reputation: 3751

Another approach would be to use Path.Combine.

Declare a function first:

Private Function CreatePath(ByVal fileName As String,
                            ByVal extension As String) As String

    Return Path.Combine("C:\", fileName & "." & extension)

End Function

Then call this wherever needed.

Dim Path as string

If txt1.Text = "A" And txt2.Text = "B" Then
     "path of my file which name is = c:/A.B"
     Path = CreatePath("A", "B")
End If

If txt1.Text = "C" And txt2.Text = "D" Then
   "path of my file which name is = c:/C.D"
   Path = CreatePath("C", "D")
End If

Upvotes: 2

Dhaval
Dhaval

Reputation: 2861

you can do this by simply writing this

"path of my file which name is = c:\" & txt1.Text & "." & txt2.Text

Upvotes: 0

OneFineDay
OneFineDay

Reputation: 9024

Use the String.Format method to concatenate them together.

Dim path As String = String.Format("c:/{0}.{1}", txt1.Text, txt2.Text)

Function:

Private Function ConPath(a As String, b As String) As String
  Return String.Format("c:/{0}.{1}", a, b)
End Function

Upvotes: 0

Related Questions