/    Sign up×
Community /Pin to ProfileBookmark

UserAccounts.CommonDialog

Greetings,

I’m using the following code to load a text file into a textarea on the page. The issue I’m having is that when cancel is selected, an error is thrown (“Unknown Name”).

[CODE]function Import(){
sBrowsePath = “C:\”;
sBrowseFilter = “All Files|*.*”;
oBrowseDialog = new ActiveXObject(“UserAccounts.CommonDialog”);

oBrowseDialog.Filter = sBrowseFilter;
oBrowseDialog.InitialDir = sBrowsePath;
oBrowseDialog.Flags = 0x80000 + 0x4 + 0x8;
oBrowseDialog.ShowOpen();

f=””;
f = fso.OpenTextFile(oBrowseDialog.FileName, ForReading);

$(“Trans”).value = f.ReadAll();
alert(“Import Complete”);
}[/CODE]

Is there a method of handling this error without sticking the following into the script to block all error?

[CODE]function blockError(){return true;}
window.onerror = blockError;[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@TNOauthorNov 13.2006 — Nevermind, I got it:

<i>
</i>function Import(){
sBrowsePath = "C:\";
sBrowseFilter = "All Files|*.*";
oBrowseDialog = new ActiveXObject("UserAccounts.CommonDialog");

<i> </i>oBrowseDialog.Filter = sBrowseFilter;
<i> </i>oBrowseDialog.InitialDir = sBrowsePath;
<i> </i>oBrowseDialog.Flags = 0x80000 + 0x4 + 0x8;
<i> </i>nResult=oBrowseDialog.ShowOpen();

<i> </i>if(nResult==0){
<i> </i> $("Trans").value+="";
<i> </i>}
<i> </i>else{
<i> </i> f="";
<i> </i> f = fso.OpenTextFile(oBrowseDialog.FileName, ForReading);

<i> </i> $("Trans").value+=f.ReadAll();
<i> </i> alert("Import Complete");
<i> </i>}
}
×

Success!

Help @TNO spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...