473,805 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting a foundfile string to a text box string

22 New Member
Hi, i have a form which displays records containing a filepath field. When a button is pressed all the filepath fields are checked and the form is refiltered to display only those with invalid file paths. Upon pressing a second button each file is searched for on the computer. Currently all the matches are just written to a list box. What i want to happen is if there is only one match then that match's file path is written to the record's file path field. I have tried to write code for this but does not work:

Expand|Select|Wrap|Line Numbers
  1.                 If fs.Execute() = 1 Then
  2.  
  3.                     URL = fs.FoundFiles
  4.  
  5.                 End If
  6.  
When this segment of code is run i get an error message: "The value you entered isn't valid for this field". I am guessing that this is because the text stored in the .foundfiles property is of the wrong type. Is there a way of outputting the file path found by the search to the url textbox either from the foundfiles property itself or the list box?
Jan 18 '08 #1
6 3302
JKing
1,206 Recognized Expert Top Contributor
Hi there,

The FoundFiles property returns an object. It's basically an array of filepaths. Therefore it is indexed and if you want to get only a single filepath you will need to specify an index.

Expand|Select|Wrap|Line Numbers
  1. fs.FoundFiles(index)
  2.  
Where index is any number from 0 to FoundFiles.Coun t - 1.

There are several ways you could do a check to see if only 1 file is returned. The count property would be great for this.

If you would like to see a more detailed example or more information about the FoundFiles property have a look in the help files.
Jan 18 '08 #2
shredder249
22 New Member
Cheers JKing, that part of the problem is now fixed. As a follow-problem I said if there were multiple files found I wanted the file paths added to a list box. I kind of managed to do this but have a problem. I set up the form so each record has a list-box. The list box isn't attached to a field or anything its just there for when there are multiple search results. The problem I'm having is that if for example a search of five files produced two matches of each file, I get all 10 results displayed in each list box on each record. I want it so only the multiple matches of each file are displayed in it's respective record, not all the matches of all the files. Is this happening because the list box isnt attached to a proper field?

Hi there,

The FoundFiles property returns an object. It's basically an array of filepaths. Therefore it is indexed and if you want to get only a single filepath you will need to specify an index.

Expand|Select|Wrap|Line Numbers
  1. fs.FoundFiles(index)
  2.  
Where index is any number from 0 to FoundFiles.Coun t - 1.

There are several ways you could do a check to see if only 1 file is returned. The count property would be great for this.

If you would like to see a more detailed example or more information about the FoundFiles property have a look in the help files.
Jan 19 '08 #3
JKing
1,206 Recognized Expert Top Contributor
If I'm understanding you correctly you want the listbox to only display the returned values of the current search and not accumulate the results from previous searches.

If this is the case you need to clear the data out of the listbox each to you add new data.

If you post your code that you are using to manipulate the listbox I can give you some more detail as how to go about doing this.
Jan 22 '08 #4
shredder249
22 New Member
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. Do Until Form.CurrentRecord = CountDisplay
  4.  
  5.             'slashfrontpos = InStrRev(URL, "\")
  6.             'URLLength = Len(URL)
  7.             'slashbackpos = URLLength - slashfrontpos
  8.             'Extract = Right(URL, slashbackpos)
  9.  
  10.             'pointfrontpos = InStrRev(URL, ".")
  11.             'URLLength = Len(URL)
  12.             'pointbackpos = URLLength - pointfrontpos
  13.             'Extension = "*." + Right(URL, pointbackpos)
  14.  
  15.             If Drive = "" Then
  16.                 Drive = Left(URL, 3)
  17.             End If
  18.  
  19.             fs.NewSearch
  20.  
  21.             With fs
  22.  
  23.                 .LookIn = "C:;D:"
  24.                 .SearchSubFolders = True
  25.                 .filename = Extract
  26.                 .MatchTextExactly = True
  27.                 .Filetype = msoFileTypeAllFiles
  28.  
  29.             End With
  30.  
  31.             If fs.Execute > 0 Then
  32.  
  33.                 'If only 1 match was found, amend record, if >1 add file paths to list box
  34.                 If fs.FoundFiles.Count = 1 Then
  35.  
  36.                     URL = fs.FoundFiles(1)
  37.                     ValidPath = -1
  38.                     corrected = corrected + 1
  39.  
  40.                 Else
  41.  
  42.                     For i = 1 To fs.FoundFiles.Count
  43.                     SearchResults.AddItem fs.FoundFiles(i)
  44.                     Next i
  45.  
  46.                     multiple = multiple + 1
  47.  
  48.                 End If
  49.  
  50.             Else
  51.  
  52.                 none = none + 1
  53.  
  54.             End If
  55.  
  56.             'If the current record number = total number of records with invalid file paths
  57.             'exit sub, if not then go to next record
  58.             If Form.CurrentRecord = TotalInvalid Then
  59.  
  60.                 If corrected > 0 Then
  61.  
  62.                     If corrected = 1 Then
  63.                         MsgBox corrected & " music file had it's file path corrected automatically."
  64.                     Else
  65.                         MsgBox corrected & " music files had their file paths corrected automatically."
  66.                     End If
  67.  
  68.                 End If
  69.  
  70.                 If multiple > 0 Then
  71.  
  72.                     SearchResults.Enabled = True
  73.  
  74.                     If multiple = 1 Then
  75.                         MsgBox multiple & " music file had more than one match in the search."
  76.                     Else
  77.                         MsgBox multiple & " music files had more than one match in the search."
  78.                     End If
  79.  
  80.                     Overwrite.Enabled = True
  81.  
  82.                 End If
  83.  
  84.                 If none > 0 Then
  85.  
  86.                     If none = 1 Then
  87.                         MsgBox none & " music file had no matches in the search."
  88.                     Else
  89.                         MsgBox none & " music files had no matches in the search."
  90.                     End If
  91.  
  92.                 End If
  93.  
  94.                 Exit Do
  95.  
  96.             Else
  97.  
  98.                 DoCmd.GoToRecord , , acNext
  99.  
  100.             End If
  101.  
  102.         Loop
  103.  
  104.  
Theres quite a lot of unrelevent stuff in the loop so i commented it out for this post. The list box is called searchresults. I have tried writing code to do it but i end up with the last records search results in all the search result boxes.

If I'm understanding you correctly you want the listbox to only display the returned values of the current search and not accumulate the results from previous searches.

If this is the case you need to clear the data out of the listbox each to you add new data.

If you post your code that you are using to manipulate the listbox I can give you some more detail as how to go about doing this.
Jan 27 '08 #5
JKing
1,206 Recognized Expert Top Contributor
Your problem is that you are constantly adding to the listbox but never removing the existing items.

There are 3 ways you can fix this.

Method 1
Expand|Select|Wrap|Line Numbers
  1. Else
  2.                     'Set value list of the list box to an empty string to clear all values
  3.                     Me.SearchResults.RowSource = ""
  4.  
  5.                     For i = 1 To fs.FoundFiles.Count
  6.  
  7.                     SearchResults.AddItem fs.FoundFiles(i)
  8.  
  9.                     Next i
  10.  
  11.                     multiple = multiple + 1
  12. End If
  13.  
Method 2
Expand|Select|Wrap|Line Numbers
  1. Else
  2.                     'Loop through the listbox and remove existing items
  3.                     Do While Me.List1.ListCount > 0
  4.                             Me.List1.RemoveItem (0)
  5.                     Loop
  6.  
  7.                     For i = 1 To fs.FoundFiles.Count
  8.  
  9.                     SearchResults.AddItem fs.FoundFiles(i)
  10.  
  11.                     Next i
  12.  
  13.                     multiple = multiple + 1
  14. End If
  15.  
Method 3
Expand|Select|Wrap|Line Numbers
  1. 'Declare a string
  2. Dim strRowSource As String
  3.  
  4. strRowSource = ""
  5. Else
  6.                     'Build String
  7.                     For i = 1 To fs.FoundFiles.Count
  8.  
  9.                     strRowSource = strRowSource & fs.FoundFiles(i) & ";"
  10.  
  11.                     Next i
  12.  
  13.                     'Set ListBox rowsource to string
  14.                     SearchResults.RowSource = strRowSource
  15.  
  16.                     multiple = multiple + 1
  17. End If
  18.  
Jan 30 '08 #6
shredder249
22 New Member
I have tried all three of the ways you suggested, but the same problem keeps occuring. This is where only the last search results are displayed in each list box. I think im putting the code in the right place i.e. in the else part of the "If fs.FoundFiles.C ount = 1 Then" statement. Is it to do with a property on the actual list box?

Your problem is that you are constantly adding to the listbox but never removing the existing items.

There are 3 ways you can fix this.

Method 1
Expand|Select|Wrap|Line Numbers
  1. Else
  2.                     'Set value list of the list box to an empty string to clear all values
  3.                     Me.SearchResults.RowSource = ""
  4.  
  5.                     For i = 1 To fs.FoundFiles.Count
  6.  
  7.                     SearchResults.AddItem fs.FoundFiles(i)
  8.  
  9.                     Next i
  10.  
  11.                     multiple = multiple + 1
  12. End If
  13.  
Method 2
Expand|Select|Wrap|Line Numbers
  1. Else
  2.                     'Loop through the listbox and remove existing items
  3.                     Do While Me.List1.ListCount > 0
  4.                             Me.List1.RemoveItem (0)
  5.                     Loop
  6.  
  7.                     For i = 1 To fs.FoundFiles.Count
  8.  
  9.                     SearchResults.AddItem fs.FoundFiles(i)
  10.  
  11.                     Next i
  12.  
  13.                     multiple = multiple + 1
  14. End If
  15.  
Method 3
Expand|Select|Wrap|Line Numbers
  1. 'Declare a string
  2. Dim strRowSource As String
  3.  
  4. strRowSource = ""
  5. Else
  6.                     'Build String
  7.                     For i = 1 To fs.FoundFiles.Count
  8.  
  9.                     strRowSource = strRowSource & fs.FoundFiles(i) & ";"
  10.  
  11.                     Next i
  12.  
  13.                     'Set ListBox rowsource to string
  14.                     SearchResults.RowSource = strRowSource
  15.  
  16.                     multiple = multiple + 1
  17. End If
  18.  
Jan 30 '08 #7

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

Similar topics

3
8699
by: Alfredo Agosti | last post by:
Hi folks, I have an Access 2000 db with a memo field. Into the memo field I put text with bold attributes, URL etc etc What I need to to is converting the rich text contained into the memo field in plain text. That's because I truncate the string text but if, when I truncate it there's a rich tag the code following the truncated string is corrupted. Don't know if it's clear enough.
2
5755
by: Asbjørn Ulsberg | last post by:
Hi. I'm trying to convert Brady Hegberg's great RTF2HTML VB 6.0 module to C#. I've managed to convert the VB code to VB.NET, which gave me the following code: Option Strict On Option Explicit On Option Compare Binary
7
2056
by: jj | last post by:
It seems simple but I had a hard time converting this small function from vb.net to C#. I even tried the software that automatically converts from vb to c# , but to no avail. Please can someone take some precious minutes to help me out. Thanks John Public Function SimpleCrypt( ByVal Text As String) As String Dim strTempChar As String, i As Integer
1
2158
by: UKuser | last post by:
Hi Guys, I have a program which converts Excel spreadsheets to Javascript and allows interactivity. However it can't convert it to PHP, which is obviously better for users to view (in case J/S is turned off). How would I go about converting some of this created code (example JS below), or is there an easier way to get PHP to do the calculations itself? I am aware of an excel-server product but this is too expensive and doesnt actually...
2
2336
by: XML newbie: Urgent pls help! | last post by:
Does anyone have a snippet of code that will convert a string to a long array? I've nearly smashed my head against the wall trying to figure this out. I'm Using vb.net 2005 Pls reply asap. I thaanku all in advance. God bless u.
12
3201
by: Frederik Vanderhaeghe | last post by:
Hi, I have a problem converting text to a double. Why doesn't the code work: If Not (txtdocbedrag.Text = "") Then Select Case ddlBedrag.SelectedIndex Case 0 Case 1
10
2002
by: Ron | last post by:
I want to calculate the surface area of a sphere from an inputed radius with option strict on. I guess I am not converting something correctly. Here is what I am doing: I have a textbox txtradius that I enter a radius into. I then have a lable that I want the surface area to be displayed in called lblsurface
3
7163
by: Jef Driesen | last post by:
How can I convert a date string to a number (e.g. a time_t value or a tm struct)? I know about the strptime function, but then I have to know the format string. And that is a problem. I'm trying to autoformat the contents of text entries in a GUI. For numbers, I'm converting the text representation to the appropriate type (using atoi, atof, ...) and converting the result back to text with the correct format (using sprintf). But this does...
1
3831
by: vcbytes | last post by:
I am having a problem with the following code: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { String^ texts = textBox1->Text; char *text = strToChars(texts); String^ shiftcs = domainUpDown1->Text; char *shiftc = strToChars(shiftcs); int shift = atoi(shiftc); char *cipher = encCCipher(text, shift); String^ ciphers = gcnew String(cipher); textBox2->Text = ciphers;
0
9716
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10604
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10356
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9179
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7644
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5676
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3839
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.