|
Thanks for the reply.
Is there a way to calculate the fastest route between multiple routes?
Thanks in advance
Regards,
Ejaz
|
|
|
|
|
Yup, multiple. I took the simple approach, and let the computer calculate each distance for all possible routes - assuming that the shortest one would be the fastest. Worked quite reasonably. You can find more advanced solutions by Googling for "Travelling Salesman Problem".
Good luck
I are Troll
|
|
|
|
|
Can you please give me any sample code to get any idea to get the distance and fastest route?
Thanks in advance
|
|
|
|
|
ejaz_pk wrote: Can you please give me any sample code to get any idea to get the distance and fastest route?
I'm sorry, but the code is copyrighted and not mine to give. I'd have turned it into an article if it wasn't Would also have been too much to post as a copy&paste sample.
Simplest solution is to measure all possible distances. That requires you to build a tree with all possible routes. The root would be your startingpoint, and if you can move to two new points from there, you'd add those as children - recursively.
Once you have all possible routes, you'd have to measure how long it is, or request it's length over some third-party. If need be free, you can use the database from Geonames.org, and calculate the length of a straight line connecting each point. You'd have to account for the earth being a big round ball, but there are formulas[^] out there that return you a length of a line on a ball. Once you have written all lengths into the tree, you find the one that gives the shortest value.
That's a simplistic algorithm that'll generate relatively satisfying results. A more complicated algorithm like Dijkstra's would be an improvement. You can also improve on this by getting "real" distances from Google for the distance between two points - but that's going to cost money if you're going to do it in bulk.
Good luck
I are Troll
|
|
|
|
|
Currently, I have a aVB.Net project that uses Ghostscript 9.01 to convert PDF to TIFF file.
It converts a color PDF to a grayscale TIFF.
Code Snippet
-------------
astrArgs(0) = "pdf2tif" 'The First Parameter is Ignored
astrArgs(1) = "-dNOPAUSE"
astrArgs(2) = "-dBATCH"
astrArgs(3) = "-r300"
astrArgs(4) = "-sDEVICE=tifflzw"
astrArgs(5) = "-sOutputFile=" & destDir & fileName.Substring(0, fileName.IndexOf(".")) & ".tif"
astrArgs(6) = path
output = CallGS(astrArgs)
-------------
What are the parameter(s) to convert a Color PDF to a "COLOR" TIFF?
|
|
|
|
|
Did you try reading the documentation on GhostScript? I found the answer in about 60 seconds by doing that. Hint, it has something to do with the DEVICE you picked. Read[^]
|
|
|
|
|
Thank you.
To share with other that might have the same question in the future.
astrArgs(4) = "-sDEVICE=tiff24nc"
|
|
|
|
|
I'd rather share the advice on reading the documentation than just a single POSSIBLE solution to the problem. Reading the docs allows a greater understanding of how GhostScript works than just the one statement you posted.
|
|
|
|
|
Hello sir
I want to develop an email application in vb without using MAPI.
Further i want to know whether MAPI can be used without outlook.
ThankQ
|
|
|
|
|
For a general question like this you could try a bit of simple research first, such as: Google[^].
I must get a clever new signature for 2011.
|
|
|
|
|
Thanks Richard , but i did that and ended up with some trial version dlls. and from google only i got this forum.
|
|
|
|
|
Did you look at the link I posted? It contains quite a few sample VB.NET mail programs.
I must get a clever new signature for 2011.
|
|
|
|
|
This[^] is C#, but I am sure it will help.
|
|
|
|
|
if your using .net framework then google system.net.mail
if your using vb "classic" then google cdosys
As barmey as a sack of badgers
Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
|
|
|
|
|
|
Hi there,
I'm been searching the net for an answer but I couldn't really get it and/or understand it
What I'm trying to accomplish is to Search my drives for the Folder's Name - and Add it to an MS Access Table
So far I have done that and works fine.
Now What I want to do is to add a Unique record ID number.(I don't want to use the auto-number function, because I'm deleting all the records every time I run the SearchFolders() and the auto-number kips incrementing otherwise)
I know this is done with the Do Until i = 1 + (Last Folder Found)
where I am lost is in the "Last folder found" I'm not sure what to reference there and also where to add it onto my code
Please take a look and help me out!
<br />
Private Sub SearchFolders(ByVal strDIR As String)<br />
Dim adoCON As New ADODB.Connection, adoRST As New ADODB.Recordset, objFSO As New FileSystemObject<br />
Dim FolderName, FolderPath, FolderDate, FolderLMod, FolderLAcc, FolderSize<br />
Dim fFolder As Folder, sFolder As Folder, i As Integer<br />
Set fFolder = objFSO.GetFolder(strDIR)<br />
For Each sFolder In fFolder.SubFolders<br />
' Search Recursively<br />
SearchFolders sFolder.Path<br />
' Get Folder Path<br />
FolderPath = sFolder.Path<br />
' get Folder Name<br />
FolderName = objFSO.GetFolder(sFolder).Name<br />
' Get Folder Date Created<br />
FolderDate = objFSO.GetFolder(sFolder).DateCreated<br />
' Get Folder Last Date Modified<br />
FolderLMod = objFSO.GetFolder(sFolder).DateLastModified<br />
' Get Folder Last Date Accessed<br />
FolderLAcc = objFSO.GetFolder(sFolder).DateLastAccessed<br />
' Get Folder Size<br />
FolderSize = objFSO.GetFolder(sFolder).Size<br />
<br />
Set adoCON = CurrentProject.Connection<br />
adoRST.Open "SELECT * FROM FoldersPath", adoCON, adOpenKeyset, adLockOptimistic<br />
With adoRST<br />
.AddNew<br />
!FolderID = i<br />
!CreatedOn = Now()<br />
!CreatedBy = Environ("UserName")<br />
!FolderName = FolderName<br />
!FolderPath = FolderPath<br />
!FolderSize = FolderSize<br />
!DateCreated = FolderDate<br />
!DateLastAccessed = FolderLAcc<br />
!DateLastModified = FolderLMod<br />
.Update<br />
End With<br />
adoRST.Close<br />
adoCON.Close<br />
Set adoRST = Nothing<br />
Set adoCON = Nothing<br />
Next<br />
Set objFSO = Nothing<br />
Set fFolder = Nothing<br />
Set sFolder = Nothing<br />
End sub<br />
|
|
|
|
|
This is VB 6, isn't it? Some tips:
1. Try to avoid variant types, they are really slow. FolderName, FolderPath, FolderDate, FolderLMod, FolderLAcc, FolderSize are variant in your snippet. Actually, you don't need them, becouse you will have this information in the fFolder properties.
2. Do not open a new recordset every time you want to add a new row. Open it before calling the function and pass it as a parameter.
3. It is usually better to do the recursive call after you have processed the current folder, I mean, add the folder you are processing, and then do the recursive calls for each subfolder into it.
4. Do not declare "i" variable into your function, just pass it as a parameter, so you will be able to increase its value on each call.
This way, your sub would look like as follows:
Sub SearchFolders(rst as Recordset, strDir as String, i as integer, objFSO As FileSystemObject)
Dim fFolder As Folder, sFolder As Folder
Set fFolder = objFSO.GetFolder(strDIR)
With rst
.AddNew
!FolderId = i
.Update
End With
For Each sFolder in fFolder.SubFolders
SearchFolders rst, sFolder.Path, i + 1, objFSO
Next
End Sub
So all you have to do is add another function which will initialize the extension paramaters (rst, i and objFSO) before calling this, and then dispose them when this Sub is finished:
Sub BeginSearchFolders(string path)
Dim objFso as New FileSystemObject
Dim rst as Recordset
SearchFolders(rst, path, 1, objFso)
rst.Close
End Sub
Edit: Forgot to add the bold parameter in the recursive call.
modified on Wednesday, March 2, 2011 8:56 AM
|
|
|
|
|
Thank you Erik! Every day I learn something new!
I'll update my code. I'm sure the way you did it will work... I'll come back if I have any problems!
|
|
|
|
|
Hi Erik! Sorry to bother again
I did the changes you suggested and some other changes to make it work
Example:
I had to put "With rst" inside "For Each sFolder" otherwise it was giving me:
SearchForFolder(): Error 91 - Object variable or with block not set
CmdSearch(): Error 3219 - Operation is not allowed in this context.
I also removed the parameter from SearchForFolders(adoCON) to CmdSearch_Click(): it was also giving me Error 91
The only problem I still have is that if in a folder I have more folders each will have the same number. So it doesn't increment with the subfolders but the folders. Example:
FolderID FolderName FolderPath
1 19 C:\Users\Name\Sample\19
1 20 C:\Users\Name\Sample\20
2 1 C:\Users\Name\Sample\20\1
2 2 C:\Users\Name\Sample\20\2
2 7 C:\Users\Name\Sample\20\7
etc
Any idea how to get around this?
New snippet
Option Compare Database
Option Explicit
Private Const BIF_RETURNONLYFSDIRS = 1
Private Const BIF_DONTGOBELOWDOMAIN = 2
Private Const BIF_EDITBOX = &H10
Private Const BIF_NEWDIALOGSTYLE = &H40
Private Const MAX_PATH = 260
Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Type BrowseInfo
hWndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type
Dim BrowsePath As String
Private Sub CmdBrowse_Click()
On Error GoTo ErrorHandler
Dim lpIDList As Long, strTitle As String, tBrwInfo As BrowseInfo
26 strTitle = "Please select your media directory:"
27 With tBrwInfo
28 .hWndOwner = Me.hwnd
29 .lpszTitle = lstrcat(strTitle, "")
30 .ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN + BIF_EDITBOX + BIF_NEWDIALOGSTYLE
End With
32 lpIDList = SHBrowseForFolder(tBrwInfo)
33 If (lpIDList) Then
34 BrowsePath = Space(MAX_PATH)
35 SHGetPathFromIDList lpIDList, BrowsePath
36 BrowsePath = Left(BrowsePath, InStr(BrowsePath, vbNullChar) - 1)
37 Me.txt_String = BrowsePath
End If
ErrorExit:
Exit Sub
ErrorHandler:
MsgBox "Error in CmdBrowse() " & vbCrLf & _
"Number: " & Err.Number & vbCrLf & _
"Description: " & Err.Description & vbCrLf & _
"Line Number: " & Erl()
Err.Clear
Resume ErrorExit
End Sub
Private Sub CmdSearch_Click()
On Error GoTo ErrorHandler
Dim adoCON As New ADODB.Connection, adoRST As New ADODB.Recordset
53 'DoCmd.SetWarnings False
54 'DoCmd.RunSQL "Delete * FROM FoldersPath"
55 'DoCmd.SetWarnings True
56 Set adoCON = CurrentProject.Connection
57 adoRST.Open "SELECT * FROM FoldersPath", adoCON, adOpenKeyset, adLockOptimistic
58 SearchForFolders adoRST, BrowsePath, 1
59 adoRST.Close
60 Set adoRST = Nothing
ErrorExit:
Exit Sub
ErrorHandler:
MsgBox "Error in CmdSearch() " & vbCrLf & _
"Number: " & Err.Number & vbCrLf & _
"Description: " & Err.Description & vbCrLf & _
"Line Number: " & Erl()
Err.Clear
Resume ErrorExit
End Sub
Sub SearchForFolders(adoRST As ADODB.Recordset, strDIR As String, intCount As Integer)
On Error GoTo ErrorHandler
Dim objFSO As New FileSystemObject, fFolder As Folder, sFolder As Folder
75 Set fFolder = objFSO.GetFolder(strDIR)
76 For Each sFolder In fFolder.SubFolders
77 SearchForFolders adoRST, sFolder.Path, intCount + 1
78 With adoRST
79 .AddNew
80 !FolderID = intCount
81 !CreatedOn = Now()
82 !CreatedBy = Environ("UserName")
83 !FolderName = objFSO.GetFolder(sFolder).Name
84 !FolderPath = sFolder.Path
85 !FolderSize = objFSO.GetFolder(sFolder).Size
86 !DateCreated = objFSO.GetFolder(sFolder).DateCreated
87 !DateLastAccessed = objFSO.GetFolder(sFolder).DateLastAccessed
88 !DateLastModified = objFSO.GetFolder(sFolder).DateLastModified
89 .Update
End With
Next
ErrorExit:
Exit Sub
ErrorHandler:
MsgBox "Error in SearchForFolder() " & vbCrLf & _
"Number: " & Err.Number & vbCrLf & _
"Description: " & Err.Description & vbCrLf & _
"Line Number: " & Erl()
Err.Clear
Resume ErrorExit
End Sub
|
|
|
|
|
Memphis76 wrote: The only problem I still have is that if in a folder I have more folders each
will have the same number
Oh, yes, you are right. Pass the index (intCount variable) by reference and increase its value prior to the recursive call:
Sub SearchForFolders(adoRST as ADODB.Recordset, strDIR as Sring, ByRef intCount as Integer)
intCount = intCount + 1
SearchForFolders adoRst, sFolder.Path, intCount
End Sub
That should work.
|
|
|
|
|
You may have noticed the result of PRE tags is much more readable than that of CODE tags...
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
I will in my next question!
|
|
|
|
|
I can't wait to see that...
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Why are you renumbering the records in the table? With the information you have in the table, I see no need to reset the numbering. But, of course, this depends on what your'e doing with the data.
Memphis76 wrote: I'm deleting all the records every time I run the SearchFolders() and the
auto-number kips incrementing otherwise) I know this is done with the Do
Until i = 1 + (Last Folder Found)
For future reference... If your doing this in a single user system, this would be fine. If you attempt to do something like this in a multi-user system, this would fail miserably. Why?
In a multi-user system, you run into a concurrency issue. If two clients run the code that returns the previous ID number at the same time, or nearly the same time, they will both generate the same "next ID" number. Since neither client may have commited to writing their new record yet, even a third client (or more) can generate the same "next ID" number.
Autonumbering fields are best left up to the database. The database will make sure there is no concurrency issue by itself. You clients don't need to know the ID number immediately. All they would need to do is either create a new record in the table then retrieve the @@IDENTITY of the new record or call some database function to "checkout" a new ID. This all, of course, means that you don't care about the identity value or if there are holes in the numbering.
|
|
|
|
|
Thanks Dave for your input!
This is gonna be a single user system... I have not found a Media Database that can give me the flexibility to "query" the data I want to pull. xbmc is the closest to what I need, however even though I can make my own triggers in the db file I don't really have the time to play with the open source and GUI xbmc has.
I have read a lot about auto-numbering and I agree with you that the best bet as you said is to leave it to the db engine.
The purpose of the FolderID is to get a sequence ID to get the Extended 'Files' Properties that I have in each folder. After testing and see that everything is working fine an auto-number field will be added as I originally did. So I guess the best explanation is a personal fight to learn something I now you guys can do and I couldn't figured out LOL
|
|
|
|
|