|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
File not founddownloading prices from the internet. I think this routine can be modified but I am hung up on the portion of the routine where is tries to open the sLocal file. If I run it as is I get Runtime error 75. I am not sure if the local file has to be created prior to running the process. If so, it the name of the folder actually "c:\deleteme.htm"? I have created a file with that name and extension in c: but when I try to run the routine I still get the file/path access error. A copy of the routines is: Option Explicit Private Declare Function URLDownloadToFile Lib "urlmon" _ Alias "URLDownloadToFileA" _ (ByVal pCaller As Long, _ ByVal szURL As String, _ ByVal szFileName As String, _ ByVal dwReserved As Long, _ ByVal lpfnCB As Long) As Long Private Const ERROR_SUCCESS As Long = 0 Private Const BINDF_GETNEWESTVERSION As Long = &H10 Private Const INTERNET_FLAG_RELOAD As Long = &H80000000 Private Sub Command1_Click() Dim sSourceUrl As String Dim sLocalFile As String Dim hfile As Long sSourceUrl = "http://vbnet.mvps.org/code/faq/fileloadtext.htm" sLocalFile = "c:\deleteme.htm" If DownloadFile(sSourceUrl, sLocalFile) Then hfile = FreeFile Open sLocalFile For Input As #hfile Debug.Print Input$(LOF(hfile), hfile) Close #hfile End If End Sub Public Function DownloadFile(sSourceUrl As String, sLocalFile As String) As Boolean DownloadFile = URLDownloadToFile(0&, sSourceUrl, sLocalFile, _ BINDF_GETNEWESTVERSION, 0&) = ERROR_SUCCESS End Function Any assistance would be appreciated. Mel "Melvin" <marvw***@columbus.rr.com> wrote As near as I can tell, the API call merely starts the download process.The process itself runs asyncronously while the function returns immediately. (That's a guess from reading the docs... it doesn't say so explicitly) In other words, you might be trying to access the file before it has arrived. Wait a while in a loop, testing to see if the file exists before trying to open it. LFS
Show quote
Hide quote
"Larry Serflaten" <serfla***@usinternet.com> wrote in message Larry, the error occurs when the procedure attempts to open the file. I news:uGBCd3I7JHA.1764@TK2MSFTNGP06.phx.gbl... > > "Melvin" <marvw***@columbus.rr.com> wrote > > As near as I can tell, the API call merely starts the download process. > The process itself runs asyncronously while the function returns > immediately. > (That's a guess from reading the docs... it doesn't say so explicitly) > > In other words, you might be trying to access the file before it has > arrived. > Wait a while in a loop, testing to see if the file exists before trying to > open it. > > LFS > > > always get a path not found error. If comment out the debug.print statement I still get the same error. The strange thing is when I first downloaded this code it seems to work. Now with the same code (I downloaded it again to be I had not inadvertently modify it) it does not work. One of life's mysteries, but very frustrating. Melvin wrote:
Show quoteHide quote > This is a follow-up to a previous post suggesting I use an API in Hi, Mel> downloading prices from the internet. I think this routine can be > modified but I am hung up on the portion of the routine where is tries > to open the sLocal file. If I run it as is I get Runtime error 75. I am > not sure if the local file has to be created prior to running the > process. If so, it the name of the folder actually "c:\deleteme.htm"? > I have created a file with that name and extension in c: but when I try > to run the routine I still get the file/path access error. > > A copy of the routines is: > > Option Explicit > > Private Declare Function URLDownloadToFile Lib "urlmon" _ > Alias "URLDownloadToFileA" _ > (ByVal pCaller As Long, _ > ByVal szURL As String, _ > ByVal szFileName As String, _ > ByVal dwReserved As Long, _ > ByVal lpfnCB As Long) As Long > > Private Const ERROR_SUCCESS As Long = 0 > Private Const BINDF_GETNEWESTVERSION As Long = &H10 > Private Const INTERNET_FLAG_RELOAD As Long = &H80000000 > > Private Sub Command1_Click() > Dim sSourceUrl As String > Dim sLocalFile As String > Dim hfile As Long > > sSourceUrl = "http://vbnet.mvps.org/code/faq/fileloadtext.htm" > sLocalFile = "c:\deleteme.htm" > > If DownloadFile(sSourceUrl, sLocalFile) Then > hfile = FreeFile > Open sLocalFile For Input As #hfile > Debug.Print Input$(LOF(hfile), hfile) > Close #hfile > End If > End Sub > > Public Function DownloadFile(sSourceUrl As String, sLocalFile As > String) As Boolean > DownloadFile = URLDownloadToFile(0&, sSourceUrl, sLocalFile, _ > BINDF_GETNEWESTVERSION, 0&) = ERROR_SUCCESS > End Function > > Any assistance would be appreciated. > > Mel I dropped that code into a new project and it worked. It didn't matter if the local file existed or not - your code created the local file or overwrote it. Graham
Show quote
Hide quote
"argusy" <arg***@slmember.on.net> wrote in message Graham, now I am really confused. Since you found it to work I copied the news:024448df$0$20662$c3e8da3@news.astraweb.com... > Melvin wrote: >> This is a follow-up to a previous post suggesting I use an API in >> downloading prices from the internet. I think this routine can be >> modified but I am hung up on the portion of the routine where is tries >> to open the sLocal file. If I run it as is I get Runtime error 75. I am >> not sure if the local file has to be created prior to running the >> process. If so, it the name of the folder actually "c:\deleteme.htm"? I >> have created a file with that name and extension in c: but when I try to >> run the routine I still get the file/path access error. >> >> A copy of the routines is: >> >> Option Explicit >> >> Private Declare Function URLDownloadToFile Lib "urlmon" _ >> Alias "URLDownloadToFileA" _ >> (ByVal pCaller As Long, _ >> ByVal szURL As String, _ >> ByVal szFileName As String, _ >> ByVal dwReserved As Long, _ >> ByVal lpfnCB As Long) As Long >> >> Private Const ERROR_SUCCESS As Long = 0 >> Private Const BINDF_GETNEWESTVERSION As Long = &H10 >> Private Const INTERNET_FLAG_RELOAD As Long = &H80000000 >> >> Private Sub Command1_Click() >> Dim sSourceUrl As String >> Dim sLocalFile As String >> Dim hfile As Long >> >> sSourceUrl = "http://vbnet.mvps.org/code/faq/fileloadtext.htm" >> sLocalFile = "c:\deleteme.htm" >> >> If DownloadFile(sSourceUrl, sLocalFile) Then >> hfile = FreeFile >> Open sLocalFile For Input As #hfile >> Debug.Print Input$(LOF(hfile), hfile) >> Close #hfile >> End If >> End Sub >> >> Public Function DownloadFile(sSourceUrl As String, sLocalFile As String) >> As Boolean >> DownloadFile = URLDownloadToFile(0&, sSourceUrl, sLocalFile, _ >> BINDF_GETNEWESTVERSION, 0&) = ERROR_SUCCESS >> End Function >> >> Any assistance would be appreciated. >> >> Mel > > Hi, Mel > > I dropped that code into a new project and it worked. > > It didn't matter if the local file existed or not - your code created the > local file or overwrote it. > Graham exact code from my original message into a new project and I still get the error message "Run-time error '75': Path/File access error". I was careful to remove any file named "deleteme.htm" from drive C and also changed the source location to drive "J:\" sameerror results. I changed the file name for drives C and I - same results. I even moved the whole process to a different computer. Same results. How can this be? Mel
Show quote
Hide quote
"Melvin" <marvw***@columbus.rr.com> wrote in message Correction.. The process DID work on another computer. Gad!!news:%23ePvKCh7JHA.1416@TK2MSFTNGP04.phx.gbl... > "argusy" <arg***@slmember.on.net> wrote in message > news:024448df$0$20662$c3e8da3@news.astraweb.com... >> Melvin wrote: >>> This is a follow-up to a previous post suggesting I use an API in >>> downloading prices from the internet. I think this routine can be >>> modified but I am hung up on the portion of the routine where is tries >>> to open the sLocal file. If I run it as is I get Runtime error 75. I am >>> not sure if the local file has to be created prior to running the >>> process. If so, it the name of the folder actually "c:\deleteme.htm"? >>> I have created a file with that name and extension in c: but when I try >>> to run the routine I still get the file/path access error. >>> >>> A copy of the routines is: >>> >>> Option Explicit >>> >>> Private Declare Function URLDownloadToFile Lib "urlmon" _ >>> Alias "URLDownloadToFileA" _ >>> (ByVal pCaller As Long, _ >>> ByVal szURL As String, _ >>> ByVal szFileName As String, _ >>> ByVal dwReserved As Long, _ >>> ByVal lpfnCB As Long) As Long >>> >>> Private Const ERROR_SUCCESS As Long = 0 >>> Private Const BINDF_GETNEWESTVERSION As Long = &H10 >>> Private Const INTERNET_FLAG_RELOAD As Long = &H80000000 >>> >>> Private Sub Command1_Click() >>> Dim sSourceUrl As String >>> Dim sLocalFile As String >>> Dim hfile As Long >>> >>> sSourceUrl = "http://vbnet.mvps.org/code/faq/fileloadtext.htm" >>> sLocalFile = "c:\deleteme.htm" >>> >>> If DownloadFile(sSourceUrl, sLocalFile) Then >>> hfile = FreeFile >>> Open sLocalFile For Input As #hfile >>> Debug.Print Input$(LOF(hfile), hfile) >>> Close #hfile >>> End If >>> End Sub >>> >>> Public Function DownloadFile(sSourceUrl As String, sLocalFile As >>> String) As Boolean >>> DownloadFile = URLDownloadToFile(0&, sSourceUrl, sLocalFile, _ >>> BINDF_GETNEWESTVERSION, 0&) = ERROR_SUCCESS >>> End Function >>> >>> Any assistance would be appreciated. >>> >>> Mel >> >> Hi, Mel >> >> I dropped that code into a new project and it worked. >> >> It didn't matter if the local file existed or not - your code created the >> local file or overwrote it. >> Graham > > > Graham, now I am really confused. Since you found it to work I copied > the exact code from my original message into a new project and I still > get the error message "Run-time error '75': Path/File access error". I was > careful to remove any file named "deleteme.htm" from drive C and also > changed the source location to drive "J:\" sameerror results. I changed > the file name for drives C and I - same results. I even moved the whole > process to a different computer. Same results. > > How can this be? > > Mel > Mel Melvin wrote:
Show quoteHide quote > "Melvin" <marvw***@columbus.rr.com> wrote in message <snip>> news:%23ePvKCh7JHA.1416@TK2MSFTNGP04.phx.gbl... >> "argusy" <arg***@slmember.on.net> wrote in message >> news:024448df$0$20662$c3e8da3@news.astraweb.com... >>> Melvin wrote: >>>> This is a follow-up to a previous post suggesting I use an API in >>>> downloading prices from the internet. I think this routine can be >>>> modified but I am hung up on the portion of the routine where is >>>> tries to open the sLocal file. If I run it as is I get Runtime error >>>> 75. I am not sure if the local file has to be created prior to >>>> running the process. If so, it the name of the folder actually >>>> "c:\deleteme.htm"? I have created a file with that name and >>>> extension in c: but when I try to run the routine I still get the >>>> file/path access error. Show quoteHide quote >>>> Any assistance would be appreciated. copying the code to a new project won't make a scrap of difference if there's a >>>> >>>> Mel >>> >>> Hi, Mel >>> >>> I dropped that code into a new project and it worked. >>> >>> It didn't matter if the local file existed or not - your code created >>> the local file or overwrote it. >>> Graham >> >> >> Graham, now I am really confused. Since you found it to work I >> copied the exact code from my original message into a new project >> and I still get the error message "Run-time error '75': Path/File >> access error". I was careful to remove any file named "deleteme.htm" >> from drive C and also changed the source location to drive "J:\" >> same error results. I changed the file name for drives C and I - same >> results. I even moved the whole process to a different computer. Same >> results. >> >> How can this be? >> >> Mel >> > > Correction.. The process DID work on another computer. Gad!! > > Mel > > folder in your target drive that's got the same name. I'm assuming you meant 'target file' instead of 'source file' (sLocalFile) just above, because it's not the source file from the internet that's creating the problem Moving the project to another computer that probably doesn't have a folder named 'deletme.htm' indicates (to me, anyway) that a same name folder really is the problem You mention you were careful to remove any file named "deleteme.htm", but did you remove a _folder_ named "deleteme.htm" To give you an idea of what I did, I copied your code to a new, standard exe form, added command1 and stepped through it. Worked fine. Leaving the "deleteme.htm" file on the c: drive, I ran it again. Worked fine. Then I set "deleteme.htm" to "read only" Same again - worked fine. Then I re-read you original post, and noticed you mentioned a _folder_(but not that it was named "deleteme.htm"). I was a bit confused over that, until I thought "Mel, you may be confusing the difference between files and folders" You won't save a file that has the same name as a directory (sorry... folder, as they're now called in Windoze) in your target drive/folder Just to make sure XP followed that rule about trying to create files and folders with the same name, I created a _folder_ named "deleteme.htm", and THEN I got the 'Run-time error '75': Path/File access error'. To me, that seems to indicate that you are trying to create a file named "deleteme.htm" in the c: root directory, when you already have a folder with the same name, stuffing up the program. Graham Melvin wrote:
Show quoteHide quote > "Melvin" <marvw***@columbus.rr.com> wrote in message And, as Nobody pointed out, administrator permissions come into play with Vista, > news:%23ePvKCh7JHA.1416@TK2MSFTNGP04.phx.gbl... >> "argusy" <arg***@slmember.on.net> wrote in message >> news:024448df$0$20662$c3e8da3@news.astraweb.com... >>> Melvin wrote: >>>> This is a follow-up to a previous post suggesting I use an API in >>>> downloading prices from the internet. I think this routine can be >>>> modified but I am hung up on the portion of the routine where is >>>> tries to open the sLocal file. If I run it as is I get Runtime error >>>> 75. I am not sure if the local file has to be created prior to >>>> running the process. If so, it the name of the folder actually >>>> "c:\deleteme.htm"? I have created a file with that name and >>>> extension in c: but when I try to run the routine I still get the >>>> file/path access error. >>>> >>>> A copy of the routines is: >>>> >>>> Option Explicit >>>> >>>> Private Declare Function URLDownloadToFile Lib "urlmon" _ >>>> Alias "URLDownloadToFileA" _ >>>> (ByVal pCaller As Long, _ >>>> ByVal szURL As String, _ >>>> ByVal szFileName As String, _ >>>> ByVal dwReserved As Long, _ >>>> ByVal lpfnCB As Long) As Long >>>> >>>> Private Const ERROR_SUCCESS As Long = 0 >>>> Private Const BINDF_GETNEWESTVERSION As Long = &H10 >>>> Private Const INTERNET_FLAG_RELOAD As Long = &H80000000 >>>> >>>> Private Sub Command1_Click() >>>> Dim sSourceUrl As String >>>> Dim sLocalFile As String >>>> Dim hfile As Long >>>> >>>> sSourceUrl = "http://vbnet.mvps.org/code/faq/fileloadtext.htm" >>>> sLocalFile = "c:\deleteme.htm" >>>> >>>> If DownloadFile(sSourceUrl, sLocalFile) Then >>>> hfile = FreeFile >>>> Open sLocalFile For Input As #hfile >>>> Debug.Print Input$(LOF(hfile), hfile) >>>> Close #hfile >>>> End If >>>> End Sub >>>> >>>> Public Function DownloadFile(sSourceUrl As String, sLocalFile As >>>> String) As Boolean >>>> DownloadFile = URLDownloadToFile(0&, sSourceUrl, sLocalFile, _ >>>> BINDF_GETNEWESTVERSION, 0&) = >>>> ERROR_SUCCESS >>>> End Function >>>> >>>> Any assistance would be appreciated. >>>> >>>> Mel >>> >>> Hi, Mel >>> >>> I dropped that code into a new project and it worked. >>> >>> It didn't matter if the local file existed or not - your code created >>> the local file or overwrote it. >>> Graham >> >> >> Graham, now I am really confused. Since you found it to work I >> copied the exact code from my original message into a new project >> and I still get the error message "Run-time error '75': Path/File >> access error". I was careful to remove any file named "deleteme.htm" >> from drive C and also changed the source location to drive "J:\" >> sameerror results. I changed the file name for drives C and I - same >> results. I even moved the whole process to a different computer. Same >> results. >> >> How can this be? >> >> Mel >> > > Correction.. The process DID work on another computer. Gad!! > > Mel > > and recommend his usage of ENVIRON to set your target file I didn't think of that, as I have administrator privileges on an XP system Graham Melvin wrote:
Show quoteHide quote > This is a follow-up to a previous post suggesting I use an API in Just re-read your post again, and noticed one word in your opening paragraph > downloading prices from the internet. I think this routine can be > modified but I am hung up on the portion of the routine where is tries > to open the sLocal file. If I run it as is I get Runtime error 75. I am > not sure if the local file has to be created prior to running the > process. If so, it the name of the folder actually "c:\deleteme.htm"? > I have created a file with that name and extension in c: but when I try > to run the routine I still get the file/path access error. > > A copy of the routines is: > > Option Explicit > > Private Declare Function URLDownloadToFile Lib "urlmon" _ > Alias "URLDownloadToFileA" _ > (ByVal pCaller As Long, _ > ByVal szURL As String, _ > ByVal szFileName As String, _ > ByVal dwReserved As Long, _ > ByVal lpfnCB As Long) As Long > > Private Const ERROR_SUCCESS As Long = 0 > Private Const BINDF_GETNEWESTVERSION As Long = &H10 > Private Const INTERNET_FLAG_RELOAD As Long = &H80000000 > > Private Sub Command1_Click() > Dim sSourceUrl As String > Dim sLocalFile As String > Dim hfile As Long > > sSourceUrl = "http://vbnet.mvps.org/code/faq/fileloadtext.htm" > sLocalFile = "c:\deleteme.htm" > > If DownloadFile(sSourceUrl, sLocalFile) Then > hfile = FreeFile > Open sLocalFile For Input As #hfile > Debug.Print Input$(LOF(hfile), hfile) > Close #hfile > End If > End Sub > > Public Function DownloadFile(sSourceUrl As String, sLocalFile As > String) As Boolean > DownloadFile = URLDownloadToFile(0&, sSourceUrl, sLocalFile, _ > BINDF_GETNEWESTVERSION, 0&) = ERROR_SUCCESS > End Function > > Any assistance would be appreciated. > > Mel that gave away the problem. open your c: drive and delete the _folder_ called "Deleteme.htm" you can't create a _file_ called deleteme.htm if a folder exists with the same name "Melvin" <marvw***@columbus.rr.com> wrote in message What OS are you using? If it's Vista, then the OS is treating you as a news:%23wwSALI7JHA.6136@TK2MSFTNGP03.phx.gbl... > This is a follow-up to a previous post suggesting I use an API in > downloading prices from the internet. I think this routine can be > modified but I am hung up on the portion of the routine where is tries to > open the sLocal file. If I run it as is I get Runtime error 75. I am not > sure if the local file has to be created prior to running the process. If > so, it the name of the folder actually "c:\deleteme.htm"? I have created > a file with that name and extension in c: but when I try to run the > routine I still get the file/path access error. limited user, even if you are an admin, so locations like the root folder and most of the C: drive, including the subfolders under "Program Files", are not writable. There are two solutions for this: 1 - Not recommended. Run your application by right clicking it and selecting "Run As Admin". This causes the app to run with administrative privileges so it can write anywhere. 2 - Recommended. Use AppData or Temp folder. You can hard code it for testing, or use one the following: sLocalFile = Environ("TEMP") & "\deleteme.htm" sLocalFile = Environ("APPDATA") & "\deleteme.htm" The above is also true for Windows 2000/XP when run by a user of the limited "Users" group. This is typically the case in businesses. Home users(and software developers) usually run as "Power Users" or "Administrators", so they don't see these permission errors.
Show quote
Hide quote
"Nobody" <nob***@nobody.com> wrote in message I am running the procedure using the run as administrator. It does not make news:%23Y15PNo7JHA.2656@TK2MSFTNGP05.phx.gbl... > "Melvin" <marvw***@columbus.rr.com> wrote in message > news:%23wwSALI7JHA.6136@TK2MSFTNGP03.phx.gbl... >> This is a follow-up to a previous post suggesting I use an API in >> downloading prices from the internet. I think this routine can be >> modified but I am hung up on the portion of the routine where is tries >> to open the sLocal file. If I run it as is I get Runtime error 75. I am >> not sure if the local file has to be created prior to running the >> process. If so, it the name of the folder actually "c:\deleteme.htm"? I >> have created a file with that name and extension in c: but when I try to >> run the routine I still get the file/path access error. > > What OS are you using? If it's Vista, then the OS is treating you as a > limited user, even if you are an admin, so locations like the root folder > and most of the C: drive, including the subfolders under "Program Files", > are not writable. There are two solutions for this: > > 1 - Not recommended. Run your application by right clicking it and > selecting "Run As Admin". This causes the app to run with administrative > privileges so it can write anywhere. > > 2 - Recommended. Use AppData or Temp folder. You can hard code it for > testing, or use one the following: > > sLocalFile = Environ("TEMP") & "\deleteme.htm" > sLocalFile = Environ("APPDATA") & "\deleteme.htm" > > The above is also true for Windows 2000/XP when run by a user of the > limited "Users" group. This is typically the case in businesses. Home > users(and software developers) usually run as "Power Users" or > "Administrators", so they don't see these permission errors. > > any difference. I'm going to see if I can find another means of accomplishing what I am trying to do and forget this procedure. Thanks for the response. Mel
Other interesting topics
Karl, I need to understand your Timer!
RAM Drive can't write to text file in Windows 7 I need a Class 101 on threading in VB6 Ghost Form Displaying forms Run-Time Error 5 - 'Invalid procedure call or argument' error msg Overcoming a MsgBox's shyness How to obtain the new GUIID key on a new build of an ActiveX DLL or an ActiveX OCX direction finding with bing |
|||||||||||||||||||||||