Page Date 2004-05-18 DD-Software |
|
|
|
MyWbtHelp current version |
|
||||
WBStudio.ForEachCollection (Utility to convert control structure from VB to WB) |
||||
;---------------------------------------------------------------------------------------------------------------------- ; Interactive Utility for use in WinBatch Studio only. ; Converts from Visual Basic Control Structure: ; "For Each ... In ... ... Next" ; to WinBatch Control Structure: ; "hEnum = ObjectCollectionOpen(objecthandle) ... While ... EndWhile" ;---------------------------------------------------------------------------------------------------------------------- ; For easy use just insert two lines into WSPOPUP.MNU, e.g.: ; _WBStudioForEachCollection \ {F7} ; Call("W:\WBT\UDF\WBStudioForEachCollection.wbt","") ; ; Modify menu entry, filename, folderpath and hotkey to your needs. ; ; For undoing of replacements use standard hotkey Ctrl-Z ; or the symbol resp. item from WinBatch Studio menu. ; ; Search starts at current cursor position in forward direction. ;---------------------------------------------------------------------------------------------------------------------- ; Detlev Dalitz.20020706.20020717 ;---------------------------------------------------------------------------------------------------------------------- iCount = 0 iCurrentLine = wGetLineNo() iCurrentCol = wGetColNo() wfPattern = "for +each +(.+) +in +(.+)" wfForward = @TRUE wfMatchCase = @FALSE wfRegExp = @TRUE wfWrap = @FALSE wfResult = wFind(wfPattern,wfForward,wfMatchCase,wfRegExp,wfWrap) If !wfResult Then Goto CANCEL Pause("WBStudioForEachCollection","Create WIL 'ObjectCollectionOpen' Loop?") ParseData (wGetWord()) ; we need param3 and param5 as var names iStartLine = ItemExtract(1,wSelInfo(),@TAB) iStartCol = ItemExtract(2,wSelInfo(),@TAB) iIndent = iStartCol + 3 wHome() wStartSel() wEnd() wEndSel() sLineHead = wGetWord() wDelete() wfPattern = " *next *" wfForward = @TRUE wfMatchCase = @FALSE wfRegExp = @TRUE wfWrap = @FALSE wfResult = wFind(wfPattern,wfForward,wfMatchCase,wfRegExp,wfWrap) wHome() wStartSel() wEnd() wEndSel() sLineFoot = wGetWord() wDelete() wEnd() wStartSel() wHome() wGotoLine(iStartLine) wEndSel() wCut() wGotoCol(iStartCol) wInsString(";") wInsLine(StrTrim(sLineHead)) wGotoCol(iStartCol) wInsLine('hEnum_%param3% = ObjectCollectionOpen(%param5%)') wInsLine('While 1') wGotoCol(iIndent) wInsLine('%param3% = ObjectCollectionNext(hEnum_%param3%)') wInsLine('If !%param3% Then Break') iLineBody = wGetLineNo() wNewLine() wGotoCol(iIndent) wInsLine('ObjectClose(%param3%)') wGotoCol(iStartCol) wInsLine('EndWhile') wInsLine('ObjectCollectionClose(hEnum_%param3%)') wInsLine('Drop(%param3%,hEnum_%param3%)') wGotoCol(iStartCol) wInsString(";") wInsString(StrTrim(sLineFoot)) wGotoLine(iLineBody) wHome() wPaste() iCount = 1 :CANCEL wClearSel() wGotoLine(iCurrentLine) wGotoCol(iCurrentCol) Message("WBStudioForEachCollection",StrCat("Replaced items: ",iCount)) Drop(iCount,iCurrentCol,iCurrentLine,iIndent,iLineBody,iStartCol,iStartLine) Drop(sLineHead,sLineFoot,wfForward,wfMatchCase,wfPattern,wfRegExp,wfResult,wfWrap) DropWild("param*") If (IntControl(77,80,0,0,0) > 0) Then Return Exit ;---------------------------------------------------------------------------------------------------------------------- ; --- test area --- ; Visual Basic control structure If Files.Count <> 0 Then For Each File In Files S = S & GenerateFileInformation(File) Next End If ; WinBatch control structure If Files.Count <> 0 Then ;For Each File In Files hEnum_File = ObjectCollectionOpen(Files) While 1 File = ObjectCollectionNext(hEnum_File) If !File Then Break S = S & GenerateFileInformation(File) ObjectClose(File) EndWhile ObjectCollectionClose(hEnum_File) Drop(File,hEnum_File) ;Next End If ;---------------------------------------------------------------------------------------------------------------------- |
||||
|
||||
WBStudio.HexToDec (Utility to convert Hex numbers to Decimal numbers) |
||||
;---------------------------------------------------------------------------------------------------------------------- ; Interactive Converter for Hex Numbers to Decimal Numbers. ; Hex Numbers must follow ; - the Visual Basic format '&H3&', '&H3D0', '"&H3&"' (enclosed in double quotes) ; - the C format '0x0000', '0x00000000L'. ; For use in WinBatchStudio Editor only. ;---------------------------------------------------------------------------------------------------------------------- ; For easy use just insert two lines into WSPOPUP.MNU, e.g.: ; _WBStudioHexToDec \ {F7} ; Call("W:\WBT\UDF\WBStudioHexToDec.wbt","") ; ; Modify menu entry, filename, folderpath and hotkey to your needs. ; ; For undoing of replacements use standard hotkey Ctrl-Z ; or the symbol resp. item from WinBatch Studio menu. ; ; Search loop starts at current cursor position in forward direction. ; ; Detlev Dalitz.20020627.20020630.20020706.20020711.20020715 ;---------------------------------------------------------------------------------------------------------------------- #DefineFunction udfHexToDec (hexstr) HexChars = "0123456789ABCDEF" hexstr = StrUpper(StrTrim(hexstr)) hexlen = StrLen(hexstr) dec = 0 For x=1 To hexlen dec = (dec<<4)+StrIndex(HexChars,StrSub(hexstr,x,1),0,@FWDSCAN)-1 Next Return (dec) ; Note: Returned negative numbers are ok. #EndFunction iCount = 0 If (RtStatus()<>10) Then Goto CANCEL ; In Studio or not? p1 = '("*&[hH][0-9a-fA-F]+&*"*)' ; Visual Basic p2 = '(0[xX][0-9a-fA-F]+[lL]*)' ; C p = StrCat(p1,"|",p2) wFind("[ ""'`]",0,0,1,0) While 1 ; wFind (SearchText, Forward, MatchCase, Regex, Wrap) If !wFind(p,1,0,1,0) Then Break ; Get selection information. SelInfo = wSelInfo() ;SelStartLine = ItemExtract(1,SelInfo,@TAB) SelStartCol = ItemExtract(2,SelInfo,@TAB) ;SelStopLine = ItemExtract(3,SelInfo,@TAB) SelStopCol = ItemExtract(4,SelInfo,@TAB) ; Check if number is comment formatted e.g. "; &H3D0" ; If so then skip and continue the search loop. wEdGoToCol(SelStartCol-1) If (wGetChar() == " ") wEdLeft() If (wGetChar() == ";") wEdGoToCol(SelStopCol) Continue EndIf EndIf ; Get the selection. wEdGoToCol(SelStartCol) wEdStartSel() wEdGoToCol(SelStopCol) wEdEndSel() sGet = wEdGetWord() ; Compute the selection and replace it. sPut = StrUpper(sGet) sPut = StrClean(sPut,"0123456789ABCDEF","",@TRUE,2) sPut = udfHexToDec(sPut) iPutLength = StrLen(sPut) wEdInsString(sPut) ; Append original number as comment at end of current line. wEdEnd() wEdInsString(" ; ") wEdInsString(sGet) ; Reposition the cursor. wEdGoToCol(SelStartCol+iPutLength) ; Make the cursor visible. wEdClearSel() ; Increment counter. iCount = iCount + 1 ; Ask for more. Pause("WBStudioHexToDec","Search and Replace again?") EndWhile :CANCEL If (iCount > 0) Then Message("WBStudioHexToDec",StrCat("Replaced items: ",iCount)) If (IntControl(77,80,0,0,0) > 0) Then Return Exit ;---------------------------------------------------------------------------------------------------------------------- ; --- test area --- "&H80000000" "&H3D0" "&H3D0" "&H3&" &H80000000 &H3D0 &H3D0 &H3& 0x80000000 0x3d0 0x3d0 0x3 0x80000000L 0x3D0 0x3D0 0x3 ;---------------------------------------------------------------------------------------------------------------------- ;*EOF* |
||||
Page Date 2004-05-18 DD-Software |
|
|
|
MyWbtHelp current version |