How to make error handling for the end user ?

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 12 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
hackoo
Posts: 103
Last visit: Tue Apr 26, 2016 9:02 am

How to make error handling for the end user ?

Post by hackoo »

Hi!

I have this HTA to compare two files, but i just want to improve it more and more. So my question is : How to make error handling for the end user when it fails or fogots to choose the file N°1 or File N°2 or both ?

i.e showing a msgbox to warn him that has missed to choose the file for example and exit the function or something else

Thank you in advance for your help !

Code: Select all

<html> 
<head> 
<title>File2Compare</title> 
<HTA:APPLICATION 
  APPLICATIONNAME="File2Compare" 
  ID="File2Compare" 
  BORDER="dialog" 
  INNERBORDER="no" 
  MAXIMIZEBUTTON="no" 
  SCROLL="no" 
  VERSION="1.0"/> 
  <style type="text/css"> 
/* Theme created by subBlue design for phpBB, http://www.subBlue.com avec queleques modification apporté par Hackoo 
  ©2001, 2005 phpBB Group, http://www.phpbb.com/    */ 
input,button 
            { 
            border:1px solid #FF6A22; 
            background-color:lightgreen; 
                font-family:Comic sans MS; 
                font-size:12px; 
                color:#804040; 
                font-weight:bold;  
                    } 
textarea{background-color:none;} 
                 
body {  
overflow:auto; 
position:relative; 
top:5px; 
left:5px; 
scrollbar-face-color: #DEE3E7; 
scrollbar-highlight-color: #FFFFFF; 
scrollbar-shadow-color: #DEE3E7; 
scrollbar-3dlight-color: #D1D7DC; 
scrollbar-arrow-color:  #006699; 
scrollbar-track-color: #EFEFEF; 
scrollbar-darkshadow-color: #98AAB1;  
background-color:lightblue; 
margin-top:4px; 
 
 
color:none; 
filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#FF7DFF', EndColorStr='lightgreen');  
        } 
         
button    {    border:1px solid #FF6A22; 
                background-color:#FFFF00; 
                font-family:Verdana; 
                font-size:9px; 
                height:14px; 
                font-weight:bold;  
                cursor:hand;    } 
 
         
div.forumline {margin-left:8px; background-color: lightblue; border: 2px #006699 solid; float:left;  
height:480px; width:250px; overflow:scroll;  } 
div.form {float:left;font-family:Comic sans MS;}  
div.toolbar {width:98%; font-family:Comic sans MS;} 
 
th,td,p { font-family: Verdana, Arial, Helvetica, sans-serif } 
hr    { height: 0px; border: solid #D1D7DC 0px; border-top-width: 1px;} 
.gen { font-size : 14px; } 
.genmed { font-size : 11px; } 
.gensmall { font-size : 10px; } 
.gen,.genmed,.gensmall { color : #000000; } 
a.gen,a.genmed,a.gensmall { color: #006699; text-decoration: none; } 
a.gen:hover,a.genmed:hover,a.gensmall:hover    { color: #DD6900; text-decoration: underline; } 
input.button {  background-color : #EFEFEF; 
                color : #000000; cursor:hand; 
                font-size: 11px; font-family: Verdana, Arial, Helvetica, sans-serif; } 
input.longbt {  background-color : #EFEFEF; 
                color : #000000; 
                font-size: 11px; font-family: Verdana, Arial, Helvetica, sans-serif; width:100px} 
.code { font-family: Courier, 'Courier New', sans-serif; font-size: 11px; color: #006600; 
        background-color: #FAFAFA; border: #D1D7DC; border-style: solid; 
        border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px } 
.quote {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: #444444; line-height: 125%; 
        background-color: #FAFAFA; border: #D1D7DC; border-style: solid; 
        border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px } 
.err{color: white; background-color: red; font-family: Verdana, Arial, Helvetica, sans-serif } 
#FolderPath{color:#FF0000} 
</style> 
</head> 
<script language="VBScript"> 
Function File2Compare(File1,File2) 
Const ForReading = 1, ForWriting = 2  
Dim objFSO,objSourceFile,objSourceFile2  
File1=File1.value 
File2=File2.value 
 
Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objSourceFile = objFSO.OpenTextFile(File1, ForReading) ' original File 
Set objSourceFile2 = objFSO.OpenTextFile(File2, ForReading) 'Modified File 
 
vrNumLigne = 0 
 Do Until objSourceFile.AtEndOfStream Or objSourceFile2.AtEndOfStream 
   vrNumLigne = vrNumLigne + 1 
   vrLigne = objSourceFile.ReadLine 
   vrLigne2 = objSourceFile2.ReadLine 
  vrComprLign = StrComp(vrLigne, vrLigne2, 1) 
  If vrComprLign = 1 Or vrComprLign = -1 Or IsNull(vrComprLign) Then 
   vrNul = "The file has not been changed" 
   vrLignDif = vrLignDif & vrNumLigne & ": " & vrLigne & vbCrLf & vrNumLigne & ": " & vrLigne2 & vbCrLf & vbCrLf 
  End If 
 Loop 
objSourceFile.Close 
objSourceFile2.Close 
If IsEmpty(vrNul) Then 
  MsgBox "The file has not been changed",64,Title 
Else 
  MsgBox vrLignDif,64,Title 
             Dim fso, f  
             Set fso = CreateObject("Scripting.FileSystemObject")  
             Set f = fso.OpenTextFile("comparaison.txt", ForWriting,true)  
             f.writeline(vrLignDif) 
    
             txtBody.value = vrLignDif 
             f.close 
End If 
End Function 
Sub Window_OnLoad 
  'This method will be called when the application loads 
  'Add your code here 
End Sub 
Sub OnClickButtonOK() 
  'This method will be called when OK is clicked 
  'Add your code here 
  window.Close 
End Sub 
 
Sub OnClickButtonCancel() 
  'This method will be called when Cancel is clicked 
  'Add your code here 
  window.Close 
End Sub 
 
</script> 
 
<center> 
<label>Fichier N°1:</label><input type="file" name="file1" id="file1" /> 
 
<label>Fichier N°2:</label><input type="file" name="file2" id="file2" /> 
 
<label>Résultat de la Comparaison:</label><br/> 
<textarea id="txtBody" rows="23" cols="80"></textarea> 
 
 
<input type="button" style="width: 140px" name="OK" id="OK" value="Comparer les Fichiers" onclick="File2Compare File1,File2"> 
<input type="button" style="width: 100px" name="Cancel" id="Cancel" value="Sortir" onclick="OnClickButtonCancel"> 
</td></tr> 
</table> 
</table> 
</body> 
</html>
User avatar
hackoo
Posts: 103
Last visit: Tue Apr 26, 2016 9:02 am

How to make error handling for the end user ?

Post by hackoo »

Hi,

I found the solution.

Code: Select all

<html> 
<head> 
<title>File2Compare</title> 
<HTA:APPLICATION 
  APPLICATIONNAME="File2Compare" 
  ID="File2Compare" 
  BORDER="dialog" 
  INNERBORDER="no" 
  MAXIMIZEBUTTON="no" 
  SCROLL="no" 
  VERSION="1.0"/> 
  <style type="text/css"> 
/* Theme created by subBlue design for phpBB, http://www.subBlue.com avec queleques modification apporté par Hackoo 
  ©2001, 2005 phpBB Group, http://www.phpbb.com/    */ 
input,button 
            { 
            border:1px solid #FF6A22; 
            background-color:lightgreen; 
                font-family:Comic sans MS; 
                font-size:12px; 
                color:#804040; 
                font-weight:bold;  
                    } 
textarea{background-color:none;} 
                 
body {  
overflow:auto; 
position:relative; 
top:5px; 
left:5px; 
scrollbar-face-color: #DEE3E7; 
scrollbar-highlight-color: #FFFFFF; 
scrollbar-shadow-color: #DEE3E7; 
scrollbar-3dlight-color: #D1D7DC; 
scrollbar-arrow-color:  #006699; 
scrollbar-track-color: #EFEFEF; 
scrollbar-darkshadow-color: #98AAB1;  
background-color:lightblue; 
margin-top:4px;<br/>color:none; 
filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#FF7DFF', EndColorStr='lightgreen');  
        } 
         
button    {    border:1px solid #FF6A22; 
                background-color:#FFFF00; 
                font-family:Verdana; 
                font-size:9px; 
                height:14px; 
                font-weight:bold;  
                cursor:hand;    } 
 
         
div.forumline {margin-left:8px; background-color: lightblue; border: 2px #006699 solid; float:left;  
height:480px; width:250px; overflow:scroll;  } 
div.form {float:left;font-family:Comic sans MS;}  
div.toolbar {width:98%; font-family:Comic sans MS;} 
 
th,td,p { font-family: Verdana, Arial, Helvetica, sans-serif } 
hr    { height: 0px; border: solid #D1D7DC 0px; border-top-width: 1px;} 
.gen { font-size : 14px; } 
.genmed { font-size : 11px; } 
.gensmall { font-size : 10px; } 
.gen,.genmed,.gensmall { color : #000000; } 
a.gen,a.genmed,a.gensmall { color: #006699; text-decoration: none; } 
a.gen:hover,a.genmed:hover,a.gensmall:hover    { color: #DD6900; text-decoration: underline; } 
input.button {  background-color : #EFEFEF; 
                color : #000000; cursor:hand; 
                font-size: 11px; font-family: Verdana, Arial, Helvetica, sans-serif; } 
input.longbt {  background-color : #EFEFEF; 
                color : #000000; 
                font-size: 11px; font-family: Verdana, Arial, Helvetica, sans-serif; width:100px} 
.code { font-family: Courier, 'Courier New', sans-serif; font-size: 11px; color: #006600; 
        background-color: #FAFAFA; border: #D1D7DC; border-style: solid; 
        border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px } 
.quote {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: #444444; line-height: 125%; 
        background-color: #FAFAFA; border: #D1D7DC; border-style: solid; 
        border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px } 
.err{color: white; background-color: red; font-family: Verdana, Arial, Helvetica, sans-serif } 
#FolderPath{color:#FF0000} 
</style> 
</head> 
<script language="VBScript"> 
Function File2Compare(File1,File2) 
Const ForReading = 1, ForWriting = 2  
Dim objFSO,objSourceFile,objSourceFile2  
File1=File1.value 
File2=File2.value 

Dim bFileNotFound 
bFileNotFound = False 
Set objFSO = CreateObject("Scripting.FileSystemObject") 
If Not objFSO.FileExists(File1) Then 
    MsgBox "File 1 does not exist",64,Title 
    bFileNotFound = True 
ElseIf Not objFSO.FileExists(File2) Then 
    MsgBox "File 2 does not exist",64,Title 
    bFileNotFound = True 
End If 
 
If Not bFileNotFound Then 
 
	Set objSourceFile = objFSO.OpenTextFile(File1, ForReading) ' original File 
	Set objSourceFile2 = objFSO.OpenTextFile(File2, ForReading) 'Modified File 
 
	vrNumLigne = 0 
	 Do Until objSourceFile.AtEndOfStream Or objSourceFile2.AtEndOfStream 
	   vrNumLigne = vrNumLigne + 1 
	   vrLigne = objSourceFile.ReadLine 
	   vrLigne2 = objSourceFile2.ReadLine 
	  vrComprLign = StrComp(vrLigne, vrLigne2, 1) 
	  If vrComprLign = 1 Or vrComprLign = -1 Or IsNull(vrComprLign) Then 
	   vrNul = "The file has not been changed" 
	   vrLignDif = vrLignDif & vrNumLigne & ": " & vrLigne & vbCrLf & vrNumLigne & ": " & vrLigne2 & vbCrLf & vbCrLf 
	  End If 
	 Loop 
	objSourceFile.Close 
	objSourceFile2.Close 
	If IsEmpty(vrNul) Then 
	  MsgBox "The file has not been changed",64,Title 
	Else 
	  MsgBox vrLignDif,64,Title 
	             Dim fso, f  
	             Set fso = CreateObject("Scripting.FileSystemObject")  
	             Set f = fso.OpenTextFile("comparaison.txt", ForWriting,true)  
	             f.writeline(vrLignDif) 
    
	             txtBody.value = vrLignDif
	             f.close 
	End If 
End If
End Function 
Sub Window_OnLoad 
  'This method will be called when the application loads 
  'Add your code here 
End Sub 
Sub OnClickButtonOK() 
  'This method will be called when OK is clicked 
  'Add your code here 
  window.Close 
End Sub 
 
Sub OnClickButtonCancel() 
  'This method will be called when Cancel is clicked 
  'Add your code here 
  window.Close 
End Sub 
 
</script> 
 
<center> 
<label>Fichier N°1:</label><input type="file" name="file1" id="file1" /> 
 
<label>Fichier N°2:</label><input type="file" name="file2" id="file2" /> 
 
<label>Résultat de la Comparaison:</label><br/> 
<textarea id="txtBody" rows="23" cols="80"></textarea> 
 
 
<input type="button" style="width: 140px" name="OK" id="OK" value="Comparer les Fichiers" onclick="File2Compare File1,File2"> 
<input type="button" style="width: 100px" name="Cancel" id="Cancel" value="Sortir" onclick="OnClickButtonCancel"> 
</td></tr> 
</table> 
</table> 
</body> 
</html>
This topic is 12 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked