Working with file names in VB

By jimmy-jam ·
I have a file name I am working with in a particular piece of code I am attempting to write (I am not a programmer). I need to work with different pieces of this file name in different parts of my code.

For example, let's say I have a file call filename.c00. In one part of my code I need the part of the file name "filename.c" and in a different part of the code I need the part of the filename "00".

I am caputring the filename in a text box on a form. I have tried to use

Right(textbox1.text, -4)

but the comiler complains that I need a ')' where the comma is. So I tried

Right(textbox1.text - 4)

but the compiler is treating the data as an interger but the data is actually alphanumerics. I tried Dimming a variable and setting it as a string and making the variable equal to right(textbox1.text - 4) but had the same result.

My Google searches have been fruitless, likely I'm not using the right key words.

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

try something like this

by lowlands In reply to Working with file names i ...

looks like you are using the Right function wrong. It needs to be something like:<br></br>
strName = Left(Textbox1.Text, <amount of characters needed)<br></br>

To get the amount of characters needed, you have to find two things, the length of your filename and the location of the "."
LengthofString = len(Textbox1.text)
CommaLocation = instr(Textbox1.text, ".")
strExtension = Right(TextBox1.text, LengthofString - CommaLocation)
StrName = Left(TextBox1.text, CommaLocation -1)</b>
if it still yaps about the textbox data being an integer, try assigning it to a variable first, <b>strMyFilename = textbox1.text</b>, then of course put strMyFileName in all the other lines.

Related Discussions

Related Forums