?
Solved

vb right function

Posted on 2011-10-11
17
Medium Priority
?
211 Views
Last Modified: 2012-05-12
I am referencing the following file. But i need to make it more dynamic.
The file name will change each time except for the last 6 characters of the file FREDDY. But I will also need to exclude the .dat section.

If I do something like

Dim Process_Claims_File – righttrim

load_success=Process_Claims_File ("\\server\Renewal_Date_Capture\RDCDATA000001FREDDY.dat", myClaims_Journal)
0
Comment
Question by:aneilg
  • 8
  • 5
  • 2
  • +2
17 Comments
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 36948228
aneilg,

Please elaborate on what you are trying to do.

Patrick
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 36948231
Not sure what your question is?

Are you trying to figure out how to locate the "new" file, based on looking for just FREDDY?

Or are you asking how to extract the FREDDY from the file name that will change each day?

~bp
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 36948234
can you please clarify the issue?
do you need the 00001 part "set" into the string, or extracted from the string?
aka where does which value come from?

if you want to "set" the value, you might do something like this:

dim strFile 
strFile = "\\server\Renewal_Date_Capture\RDCDATA$$$$$$FREDDY.dat"
strFile = replace(strFile, "$$$$$$", right( "000000" & your_number , 6 )) 
load_success=Process_Claims_File (strFile, myClaims_Journal) 

Open in new window


hope this helps
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:Alan_White
ID: 36948242
Sorry, I dont really understand the question, can you try again?

In general, the Right function will return the rightmost characters of a string.  eg wscript.echo  Right("ThisIsAnExample",3)  will produce "ple"

The Left function will do similar on the leftmost characters.  eg wscript.echo  Left("ThisIsAnExample",3) will produce "Thi"

Perhaps you want the leftmost characters excluding the rightmost 6 (for FREDDY) and 4 (for .dat)?

If so, Left(strYourVarilable,Len(strYourVariable)-10) should produce that.

Still not sure what you are going to do with that though?
0
 

Author Comment

by:aneilg
ID: 36948540
hello sorry.
i just need to Identify the file name from freddy.
the location will always be the same.

so if the file is ("\\server\Renewal_Date_Capture\RDCDATA000001FREDDY.dat", myClaims_Journal)
i know i nedd to process file freddy.

or if the file is ("\\server\Renewal_Date_Capture\RDCDATA000001abcdef.dat", myClaims_Journal)
i know i nedd to process file abcdef.
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 36948579
How about this:

strFile = "\\server\Renewal_Date_Capture\RDCDATA000001abcdef.dat"
strPiece = Right(Left(strFile, Len(strFile)-4), 6)

Open in new window

~bp
0
 

Author Comment

by:aneilg
ID: 36954470
thanks.
0
 

Author Comment

by:aneilg
ID: 36955487
sorry guys my mistake.

basically what i want to do is read a file from a path.
 ("\\server\Renewal_Date_Capture\RDCDATA000001FREDDY.dat", myClaims_Journal)

i want to take out RDCDATA000001FREDDY.dat and use that file name.
0
 
LVL 10

Expert Comment

by:Alan_White
ID: 36955534
So, are you saying that there is a file in a folder that you want to use and that it has a name that you don't know but it will end in FREDDY.dat?
0
 

Author Comment

by:aneilg
ID: 36955565
Sorry for the confusion guys.

What I want to do is just get the .dat file name, irrespective of what the file is called.
I want to get the name of the .dat file from the folder.
0
 

Author Comment

by:aneilg
ID: 36955572
on my folder, the faile name can be anything.
("\\server\Renewal_Date_Capture\RDCDATA000001FREDDY.dat", myClaims_Journal)

or
("\\server\Renewal_Date_Capture\RDCDATA000001PAUL.dat", myClaims_Journal)

i need to get the .dat file name.
0
 
LVL 10

Expert Comment

by:Alan_White
ID: 36955666
Okay, we are getting somewhere.

Is the path and partial filename always the same?

Path is always \\server\Renewal_Date_Capture?
File name always starts with RDCDATA000001?
File name always ends with .dat?

Will there be many files in this folder when the script runs or just one?
0
 

Author Comment

by:aneilg
ID: 36955741
thanks for your help alan.

the folder will always be the same.
the file will NOT start with RDCDATA000001.
the file will always end in .dat.

so i need the name of the full .dat file to use.
0
 
LVL 10

Expert Comment

by:Alan_White
ID: 36956000
And there will only be one .dat file in the folder when you run the script?
0
 
LVL 10

Accepted Solution

by:
Alan_White earned 1000 total points
ID: 36956182
Have a play around with this function I've knocked up, it might be close to what you are after.
wscript.echo getDatFileName("\\server\Renewal_Date_Capture")

Function getDatFileName(sFolder)
	
	getDatFileName = "Not Found"

	Dim oFSO, oFolder, oFile
	Set oFSO = CreateObject("Scripting.FileSystemObject")

	If oFSO.FolderExists(sFolder) Then
		Set oFolder = oFSO.GetFolder(sFolder)
		For Each oFile In oFolder.Files
			If LCase(Right(oFile.Name,4)) = ".dat" Then
				getDatFileName = oFile.Name
			End If
		Next
	End If	

End Function

Open in new window

0
 

Author Comment

by:aneilg
ID: 36961019
thanks alan.

really do Appreciate your help.
0
 

Author Closing Comment

by:aneilg
ID: 36985913
fandabidozi
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question