473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need a working sample code for StrReverse and InStr

imrosie
222 100+
Hello,

I don't completely understand the working of these functions, but it's been suggested that these will give me what I need.
I have a database that pulls in image files (stores the absolute path in database). The image shows up in my subform. The file name is displayed in a form control called 'image description'. The problem is it displays the entire link, such as c:\imageCats\GizmotheCat.jpg (absolute path)....

End user cah 'browse' to any folder they may have stored pictures to retrieve an image. So the absolute path will change with each end-user. I don't want to hardcode a specific path. However, I do need the absolute path to an image stored and only display in the control a name, i.e. GizmotheCat.

I'm looking for real working example code for StrReverse (InStr), so I can somehow reverse the string, cut off the 'GizmotheCat.jpg and display only the GizmotheCat in this control. I also like the .jpg to go into another control box. I've received some examples, but can't get them working in my form.

Does anyone have something like this? Thanks in advance.

Rosie
Jun 13 '07 #1
7 3734
MMcCarthy
14,534 Expert Mod 8TB
This function should do what you want.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Function getFName(path As String) As String
  3. Dim fName As String
  4. Dim pos1 As Integer
  5. Dim pos2 As Integer
  6. Dim tmpPos As Integer
  7.     pos1 = 1
  8.     Do Until (InStr(pos1, path, "\") = 0)
  9.         tmpPos = InStr(pos1, path, "\")
  10.         pos1 = tmpPos + 1
  11.     Loop
  12.     pos2 = InStr(path, ".") - pos1
  13.     fName = Mid(path, pos1, pos2)
  14.     getFName = fName
  15.  
  16. End Function
  17.  
Jun 16 '07 #2
ADezii
8,834 Expert 8TB
Hello,

I don't completely understand the working of these functions, but it's been suggested that these will give me what I need.
I have a database that pulls in image files (stores the absolute path in database). The image shows up in my subform. The file name is displayed in a form control called 'image description'. The problem is it displays the entire link, such as c:\imageCats\GizmotheCat.jpg (absolute path)....

End user cah 'browse' to any folder they may have stored pictures to retrieve an image. So the absolute path will change with each end-user. I don't want to hardcode a specific path. However, I do need the absolute path to an image stored and only display in the control a name, i.e. GizmotheCat.

I'm looking for real working example code for StrReverse (InStr), so I can somehow reverse the string, cut off the 'GizmotheCat.jpg and display only the GizmotheCat in this control. I also like the .jpg to go into another control box. I've received some examples, but can't get them working in my form.

Does anyone have something like this? Thanks in advance.

Rosie
Rosie, Rosie, I thought we covered all this?
Jun 16 '07 #3
FishVal
2,653 Expert 2GB
Hello,

I don't completely understand the working of these functions, but it's been suggested that these will give me what I need.
I have a database that pulls in image files (stores the absolute path in database). The image shows up in my subform. The file name is displayed in a form control called 'image description'. The problem is it displays the entire link, such as c:\imageCats\GizmotheCat.jpg (absolute path)....

End user cah 'browse' to any folder they may have stored pictures to retrieve an image. So the absolute path will change with each end-user. I don't want to hardcode a specific path. However, I do need the absolute path to an image stored and only display in the control a name, i.e. GizmotheCat.

I'm looking for real working example code for StrReverse (InStr), so I can somehow reverse the string, cut off the 'GizmotheCat.jpg and display only the GizmotheCat in this control. I also like the .jpg to go into another control box. I've received some examples, but can't get them working in my form.

Does anyone have something like this? Thanks in advance.

Rosie
Hi, Rosie.

Now I've got how irrelevant was my advice to use custom class. Remember? ;)

Here I'm suggesting you the following solution.

1. Put the code below to a public module.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Function ExtractFileExt(varFullPath As Variant) As String
  3. If IsNull(varFullPath) Then Exit Function
  4. ExtractFileExt = StrReverse(Left(StrReverse(varFullPath), _
  5. InStr(1, StrReverse(varFullPath), ".")))
  6. End Function
  7.  
  8. Public Function ExtractFileName(varFullPath As Variant) As String
  9. If IsNull(varFullPath) Then Exit Function
  10. ExtractFileName = StrReverse(Mid(StrReverse(varFullPath), _
  11. InStr(1, StrReverse(varFullPath), ".") + 1, _
  12. InStr(1, StrReverse(varFullPath), "\") - _
  13. InStr(1, StrReverse(varFullPath), ".") - 1))
  14. End Function
  15.  
  16.  
Specially for you 4 "Instr"s and 8 "StrReverse"s. ;)

The following assumes your form field with picture full path has name "txtPictureFullPath".

2. Set DataSource of the field displaying file extension to
=ExtractFileExt([txtPictureFullPath])

3. Set DataSource of the field displaying file name to
=ExtractFileName([txtPictureFullPath])

Hope that this will help you.

Goooooogluck.
Jun 16 '07 #4
imrosie
222 100+
Rosie, Rosie, I thought we covered all this?

We did and it's working fine...I posted this days ago and I don't know how to close the discussion other than to tell everyone, that I've got a working solution.

Thanks ADezii. take care

Rosie
Jun 17 '07 #5
imrosie
222 100+
Hi, Rosie.

Now I've got how irrelevant was my advice to use custom class. Remember? ;)

Here I'm suggesting you the following solution.

1. Put the code below to a public module.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Function ExtractFileExt(varFullPath As Variant) As String
  3. If IsNull(varFullPath) Then Exit Function
  4. ExtractFileExt = StrReverse(Left(StrReverse(varFullPath), _
  5. InStr(1, StrReverse(varFullPath), ".")))
  6. End Function
  7.  
  8. Public Function ExtractFileName(varFullPath As Variant) As String
  9. If IsNull(varFullPath) Then Exit Function
  10. ExtractFileName = StrReverse(Mid(StrReverse(varFullPath), _
  11. InStr(1, StrReverse(varFullPath), ".") + 1, _
  12. InStr(1, StrReverse(varFullPath), "\") - _
  13. InStr(1, StrReverse(varFullPath), ".") - 1))
  14. End Function
  15.  
  16.  
Specially for you 4 "Instr"s and 8 "StrReverse"s. ;)

The following assumes your form field with picture full path has name "txtPictureFullPath".

2. Set DataSource of the field displaying file extension to
=ExtractFileExt([txtPictureFullPath])

3. Set DataSource of the field displaying file name to
=ExtractFileName([txtPictureFullPath])

Hope that this will help you.

Goooooogluck.
Thanks so much FishVal....I will test this out and if it works, I'll use it in a future project. ADezii gave me one that I've got working. so thanks again. I'll post back to let you know if it also fixed my issue. thanks and take care.
Jun 17 '07 #6
NeoPa
32,556 Expert Mod 16PB
Rosie, In future, simply reply to the thread that you have a solution. That will let everyone know that further solutions are not required. I will not close the thread, as it seems obvious now that no further advice is required anyway.

Thanks to our expert MissingLinq for bringing this to my attention.
Jun 17 '07 #7
ADezii
8,834 Expert 8TB
We did and it's working fine...I posted this days ago and I don't know how to close the discussion other than to tell everyone, that I've got a working solution.

Thanks ADezii. take care

Rosie
It was a pleasure working with you.
Jun 17 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Chris Michael | last post by:
Hello everybody, Newbie here. I've been working on this for the last two days and I can't figure out where this problem is. I think it's something so obvious, but I can't see it! OK, firstly...
3
by: Danny | last post by:
I am trying to do a regular expression to search for a url so anything that has http:\\www.hellothere.com but may not have the http:\\ and may not have the www and may not have http:\\www and...
5
by: Theresa Hancock via AccessMonster.com | last post by:
I have an Excel table I need to import into Access. The name is entered into one field "Name". I'd like to have two fields in Access, FirstName and LastName. How do I do this. -- Message posted...
21
by: google | last post by:
I'm trying to implement something that would speed up data entry. I'd like to be able to take a string, and increment ONLY the right-most numerical characters by one. The type structure of the...
22
by: John Cobb | last post by:
I've removed the Microsoft.VisualBasic import from my VB.Net project and am in the process of replacing the vb6 compatible calls with native .Net i.e. system.datetime.now instead of Now, variable...
8
by: jimmy | last post by:
I am working on a project which tracks 'bad' words in IE and im using a For loop to check for an array of words in he address bar. I have included the broken code below. Any pointers on why it isnt...
23
by: Rex | last post by:
Hi I want to write a procedure which takes in a string of names seperated by a whitespace and puts commas at each whitespace the last name however, should have "and" before it. Let me explain...
5
by: talktozee | last post by:
Hello, everyone! Here's are the basics: 1. The query looks at all positions that are active and haven't been filled. 2. It then has to look at every single position and determine three...
4
by: thesinnerishere | last post by:
i have created a program(link-generator) which is static in nature(it works correctly) meaning that this program must find the symbol { } first for it to operate properly.how can i make it dynamic so...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.