Leaderboard
Popular Content
Showing content with the highest reputation on 03/26/2013 in all areas
-
Hirajoshi Wind Chime
jaberwacky reacted to czardas for a topic
Hirajoshi Wind Chime Let me introduce you to the AutoIt Hirajoshi Wind Chime. There are seven 15 different chime arrangements to choose from : Gong, Okinawa, Insen, Nando-kyemyonjo, Kata-kumoi, Hirajoshi and Chaio. Thanks to the authors of the original Midi UDF. Without their contributions, Hirajoshi Wind Chime would never have existed. Latest Version is in #include 'MidiOutLite.au3' Global $open = _MidiOutOpen() ; $iChime - values range from 0 to 14 ; 0 .... Gong (CN) ..................... C D E G A C ; 1 .... Okinawa (JP) .................. C E F G B C ; 2 .... Insen (JP) .................... C Db F G Bb C ; 3 .... Nando-kyemyonjo (KR) .......... C D Eb F G C ; 4 .... Kata-kumoi (JP) ............... C D Eb F Ab C ; 5 .... Hirajoshi (JP) ................ C D Eb G Ab C ; 6 .... Chaio (CN) .................... C D F Ab Bb C ; 7 .... Ritsu (JP) .................... C Db Eb F Ab Bb C ; 8 .... Niagari (JP) .................. C Db F G Ab Bb C ; 9 .... Takemitsu Tree Line Mode 1 (JP) C D Eb Gb Ab B C ; 10 ... Takemitsu Tree Line Mode 2 (JP) C D Eb Gb Ab Bb C ; 11 ... P'yongio (KR) ................. C D F G A Bb C ; 12 ... Eskimo (1) .................... C D Eb F G Bb C ; 13 ... Eskimo (2) .................... C D E Gb Ab B C ; 14 ... Stravinsky .................... C Db Eb E F# G A Bb C HotKeySet("{ESC}", "_Quit") _AddLightBreeze(Random(0,14,1), 1) ; First param - Chime number 0 to 14 - see list. ; Second param - Randomise chimes 0 or 1. ; Third param Maximum calm in miliseconds. Func _AddLightBreeze($iChime, $iRandomise = 0, $iMaxCalm = 30000) Local $aChime = _LoadChime($iChime) Local $iRandomCalm, $iRandomNote, $iVolume = 65535, $iTranspose = 12 _MidiOutShortMsg($open,256 * 14 + 192) _MidiOutSetVolume() While 1 $iRandomNote = Random(0,7,1) _MidiOutshortmsg($open,$MIDINOTE[ $aChime[ $iRandomNote ] + $iTranspose ][0]) _MidiOutshortmsg($open,$MIDINOTE[ $aChime[ $iRandomNote ] + $iTranspose + 12 ][0]) ; Octave added. $iRandomCalm = Random(20,1000,1) If $iRandomCalm > 950 Then Sleep(Random(0,$iMaxCalm,1)) $iVolume = 65535 _MidiOutSetVolume() ElseIf $iRandomCalm > 750 Then Sleep(Int($iRandomCalm*Random(0.5,5))) $iVolume = Int($iVolume*1.2) If ($iVolume < 32768) Or ($iVolume > 65535) Then $iVolume = 65535 _MidiOutSetVolume($iVolume) Else Sleep(Random(50,500,1)) $iVolume = Int($iVolume*.9) If $iVolume < 6554 Then $iVolume = 32768 _MidiOutSetVolume($iVolume) EndIf If $iRandomise And Not Random(0, 10, 1) Then $aChime = _LoadChime(Random(0, 14, 1)) ; $iTranspose = Random(7, 18, 1) ; Optional - transposes the notes. EndIf WEnd EndFunc Func _LoadChime($iChime = 3) Local $aScale[15][8] = _ [[39,41,43,46,48,51,53,55], _ ; Gong [39,43,44,46,50,51,55,56], _ ; Okinawa [37,39,40,44,46,49,51,53], _ ; Insen [39,41,42,44,46,51,53,54], _ ; Nando-kyemyonjo [39,41,42,44,47,51,53,54], _ ; Kata-kumoi [39,41,42,46,47,51,53,54], _ ; Hirajoshi [37,39,41,44,46,49,51,53], _ ; Chaio [37,39,40,42,44,47,49,51], _ ; Ritsu [37,39,40,43,44,46,49,51], _ ; Niagari [39,41,42,45,47,50,51,53], _ ; Takemitsu Tree Line Mode 1 [37,39,41,42,45,47,49,51], _ ; Takemitsu Tree Line Mode 2 [39,41,44,46,48,49,51,53], _ ; P'yongio [37,39,41,42,44,46,49,51], _ ; Eskimo (1) [39,41,43,45,47,50,51,53], _ ; Eskimo (2) [40,41,43,44,46,47,49,50]] ; Stravinsky Local $aTemp[8] For $i = 0 To 7 $aTemp[$i] = $aScale[$iChime][$i] Next Return $aTemp EndFunc Func _Quit() Sleep(1000) ; Allow the volume to fade a little before closing. _MidiOutSetVolume() _MidiOutclose($open) Exit EndFuncCredit must go to Eynstyne and Ascend4nt for the functions in the following script. MidiOutLite.au3 ; This code is a minimalistic version of Ascend4nt's adaptation of the original midi UDF by Eynstyne. ; For the original source and a full description of all midi constants (including instruments): see => ; http://www.autoitscript.com/forum/topic/37072-midi-udf/page__view__findpost__p__810725 ; The selected functions are for midi output only, so any musical input needs to be hard coded. ; The midi note values are now stored in a 2D array, as opposed to using individual constants. ; One line of code has been added to _MidiOutSetVolume to ensure equal output on both speakers. ; Default midi volume has been set to maximum. Const $MIDINOTE[88][2] = [ _ ; [?][0] = Play, [?][1] = Stop [0x00401590,0x00001590], _ ; [0][?] .... A [0x00401690,0x00001690], _ ; [1][?] .... Bb [0x00401790,0x00001790], _ ; [2][?] .... B [0x00401890,0x00001890], _ ; [3][?] .... C First Octave [0x00401990,0x00001990], _ ; [4][?] .... Db [0x00401A90,0x00001A90], _ ; [5][?] .... D [0x00401B90,0x00001B90], _ ; [6][?] .... Eb [0x00401C90,0x00001C90], _ ; [7][?] .... E [0x00401D90,0x00001D90], _ ; [8][?] .... F [0x00401E90,0x00001E90], _ ; [9][?] .... Gb [0x00401F90,0x00001F90], _ ; [10][?] ... G [0x00402090,0x00002090], _ ; [11][?] ... Ab [0x00402190,0x00002190], _ ; [12][?] ... A [0x00402290,0x00002290], _ ; [13][?] ... Bb [0x00402390,0x00002390], _ ; [14][?] ... B [0x00402490,0x00002490], _ ; [15][?] ... C Second Octave [0x00402590,0x00002590], _ ; [16][?] ... Db [0x00402690,0x00002690], _ ; [17][?] ... D [0x00402790,0x00002790], _ ; [18][?] ... Eb [0x00402890,0x00002890], _ ; [19][?] ... E [0x00402990,0x00002990], _ ; [20][?] ... F [0x00402A90,0x00002A90], _ ; [21][?] ... Gb [0x00402B90,0x00002B90], _ ; [22][?] ... G [0x00402C90,0x00002C90], _ ; [23][?] ... Ab [0x00402D90,0x00002D90], _ ; [24][?] ... A [0x00402E90,0x00002E90], _ ; [25][?] ... Bb [0x00402F90,0x00002F90], _ ; [26][?] ... B [0x00403090,0x00003090], _ ; [27][?] ... C Third Octave [0x00403190,0x00003190], _ ; [28][?] ... Db [0x00403290,0x00003290], _ ; [29][?] ... D [0x00403390,0x00003390], _ ; [30][?] ... Eb [0x00403490,0x00003490], _ ; [31][?] ... E [0x00403590,0x00003590], _ ; [32][?] ... F [0x00403690,0x00003690], _ ; [33][?] ... Gb [0x00403790,0x00003790], _ ; [34][?] ... G [0x00403890,0x00003890], _ ; [35][?] ... Ab [0x00403990,0x00003990], _ ; [36][?] ... A [0x00403A90,0x00003A90], _ ; [37][?] ... Bb [0x00403B90,0x00003B90], _ ; [38][?] ... B [0x00403C90,0x00003C90], _ ; [39][?] ... C Fourth Octave - Middle C [0x00403D90,0x00003D90], _ ; [40][?] ... Db [0x00403E90,0x00003E90], _ ; [41][?] ... D [0x00403F90,0x00003F90], _ ; [42][?] ... Eb [0x00404090,0x00004090], _ ; [43][?] ... E [0x00404190,0x00004190], _ ; [44][?] ... F [0x00404290,0x00004290], _ ; [45][?] ... Gb [0x00404390,0x00004390], _ ; [46][?] ... G [0x00404490,0x00004490], _ ; [47][?] ... Ab [0x00404590,0x00004590], _ ; [48][?] ... A [0x00404690,0x00004690], _ ; [49][?] ... Bb [0x00404790,0x00004790], _ ; [50][?] ... B [0x00404890,0x00004890], _ ; [51][?] ... C Fifth Octave [0x00404990,0x00004990], _ ; [52][?] ... Db [0x00404A90,0x00004A90], _ ; [53][?] ... D [0x00404B90,0x00004B90], _ ; [54][?] ... Eb [0x00404C90,0x00004C90], _ ; [55][?] ... E [0x00404D90,0x00004D90], _ ; [56][?] ... F [0x00404E90,0x00004E90], _ ; [57][?] ... Gb [0x00404F90,0x00004F90], _ ; [58][?] ... G [0x00405090,0x00005090], _ ; [59][?] ... Ab [0x00405190,0x00005190], _ ; [60][?] ... A [0x00405290,0x00005290], _ ; [61][?] ... Bb [0x00405390,0x00005390], _ ; [62][?] ... B [0x00405490,0x00005490], _ ; [63][?] ... C Sixth Octave [0x00405590,0x00005590], _ ; [64][?] ... Db [0x00405690,0x00005690], _ ; [65][?] ... D [0x00405790,0x00005790], _ ; [66][?] ... Eb [0x00405890,0x00005890], _ ; [67][?] ... E [0x00405990,0x00005990], _ ; [68][?] ... F [0x00405A90,0x00005A90], _ ; [69][?] ... Gb [0x00405B90,0x00005B90], _ ; [70][?] ... G [0x00405C90,0x00005C90], _ ; [71][?] ... Ab [0x00405D90,0x00005D90], _ ; [72][?] ... A [0x00405E90,0x00005E90], _ ; [73][?] ... Bb [0x00405F90,0x00005F90], _ ; [74][?] ... B [0x00406090,0x00006090], _ ; [75][?] ... C Seventh Octave [0x00406190,0x00006190], _ ; [76][?] ... Db [0x00406290,0x00006290], _ ; [77][?] ... D [0x00406390,0x00006390], _ ; [78][?] ... Eb [0x00406490,0x00006490], _ ; [79][?] ... E [0x00406590,0x00006590], _ ; [80][?] ... F [0x00406690,0x00006690], _ ; [81][?] ... Gb [0x00406790,0x00006790], _ ; [82][?] ... G [0x00406890,0x00006890], _ ; [83][?] ... Ab [0x00406990,0x00006990], _ ; [84][?] ... A [0x00406A90,0x00006A90], _ ; [85][?] ... Bb [0x00406B90,0x00006B90], _ ; [86][?] ... B [0x00406C90,0x00006C90]] ; [87][?] ... C Eighth Octave ;======================================================= ;Retrieves a MIDI handle and Opens the Device ;Parameters(Optional) - Device ID, Window Callback, ; instance, flags ;Author : Eynstyne ;Library : Microsoft winmm.dll ;======================================================= Func _MidiOutOpen($devid = 0, $callback = 0, $instance = 0, $flags = 0) Local $ret = DllCall("winmm.dll", "long", "midiOutOpen", "handle*", 0, "int", $devid, "dword_ptr", $callback, "dword_ptr", $instance, "long", $flags) If @error Then Return SetError(@error,0,0) If $ret[0] Then Return SetError(-1,$ret[0],0) Return $ret[1] EndFunc ;==>_MidiOutOpen ;======================================================= ;======================================================= ;Closes Midi Output/Input devices ;Parameters - MidiHandle ;Author : Eynstyne ;Library : Microsoft winmm.dll ;======================================================= Func _MidiOutClose ($hmidiout) Local $ret = DllCall("winmm.dll", "long", "midiOutClose", "handle", $hmidiout) If @error Then Return SetError(@error,0,0) If $ret[0] Then Return SetError(-1,$ret[0],0) Return $ret[0] EndFunc ;==>_MidiOutClose ;======================================================= ;Gets the Mixer Volume for MIDI ;Parameters - None ;Author : Eynstyne ;Library : Microsoft winmm.dll ;======================================================= Func _MidiOutGetVolume ($devid = 0) Local $ret = DllCall("winmm.dll", "long", "midiOutGetVolume", "handle", $devid, "dword*",0) If @error Then Return SetError(@error,0,0) If $ret[0] Then Return SetError(-1,$ret[0],0) Return $ret[2] EndFunc ;==>_MidiOutGetVolume ;======================================================= ;Sets the Mixer Volume for MIDI ;Parameters - Volume (0 - 65535) ;Author : Eynstyne ;Library : Microsoft winmm.dll ;======================================================= Func _MidiOutSetVolume($iVolume = 65535, $devid = 0) Local $iMixVolume=BitAND($iVolume,0xFFFF)+BitShift(BitAND($iVolume,0xFFFF),-16) ; From Ascend4nt Local $ret = DllCall("winmm.dll", "long", "midiOutSetVolume", "handle", $devid, "int", $iMixVolume) If @error Then Return SetError(@error,0,0) If $ret[0] Then Return SetError(-1,$ret[0],0) Return $ret[0] EndFunc ;==> _MidiOutSetVolume ;======================================================= ;MIDI Message Send Function ;Parameters - Message as Hexcode or Constant ;Author : Eynstyne ;Library : Microsoft winmm.dll ;======================================================= Func _MidiOutShortMsg($hmidiout, $msg) Local $ret = DllCall("winmm.dll", "long", "midiOutShortMsg", "handle", $hmidiout, "long", $msg) If @error Then Return SetError(@error,0,0) If $ret[0] Then Return SetError(-1,$ret[0],0) Return $ret[0] EndFunc ;==>_MidiOutShortMsg1 point -
; #FUNCTION# ;================================================================================= ; Name...........: _StringSplitRegExp ; Description ...: Split a string according to a regular expression. ; Syntax.........: _StringSplitRegExp($sString, $sPattern[, $flag = 0[, $sIncludeMatch = 0[, $iCount = 0]]]) ; Parameters ....: $sString - String: String to split. ; $sPattern - String: Regular expression to split on. ; $flag - return count in the first element ; $sIncludeMatch - ; |0 - To exclude a divider (by default) ; |1 - To attach a divider at the left ; |2 - To attach a divider on the right ; $iCount - The number of times to execute the replacement in the string ; Return values .: Success - Array: Array of substrings, the total is in $array[0]. ; Failure - Array: The count is 1 ($array[0]) and the full string is returned ($array[1]) and sets @error: ; |1 No suitable placeholder delimiter could be constructed. ; |2 Bad RegExp pattern, @extended contains the offset of the error in the pattern. ; |3 Delimiter not found. ; Author ........: AZJIO, weaponx, dany ; ============================================================================================ ; Имя функции ...: _StringSplitRegExp ; Описание ........: Разделяет строки с помощью регулярного выражения ; Синтаксис.......: _StringSplitRegExp($sString, $sPattern[, $flag = 0[, $sIncludeMatch = 0[, $iCount = 0]]]) ; Параметры: ; $sString - Строка для деления на части ; $sPattern - Регулярное выражение определяющая строку, которая будет разделителем ; $flag - По умолчанию 0 - возвращает количество элементов в первый элемент массива, иначе не возвращает ; $sIncludeMatch - Включить раздедитель в результат ; |0 - Исключить разделитель (по умолчанию) ; |1 - Разделитель присоединять слева ; |2 - Разделитель присоединять справа ; $iCount - количество выполненных замен ; Возвращаемое значение: Успешно - Массив строк, в котором $array[0] содержит количество строк в массиве ; Неудачно - Массив в котором исходная строка помещается в $array[1], и устанавливает @error: ; |0 - нет ошибок ; |1 - Внутренняя ошибка, не удалось выбрать подстановочный разделитель ; |2 - Регулярное выражение содержит ошибку ; |3 - Регулярное выражение не находит разделитель в строке ; Автор ..........: AZJIO, weaponx, dany ; ============================================================================================ ; http://www.autoitscript.com/forum/topic/139260-autoit-snippets/?p=1065198 ; http://www.autoitscript.com/forum/topic/139260-autoit-snippets/page__st__140#entry1036931 ; http://www.autoitscript.com/forum/topic/65662-stringsplitregexp/ Func _StringSplitRegExp($sString, $sPattern, $flag = 0, $sIncludeMatch = 0, $iCount = 0) Local $sSplit, $sDelim, $sReplace, $Toggle, $iPos = 1 If IsBinary($sString) Then $sString = Hex($sString) $sDelim = Chr(1) Local $aError[2] = [1, $sString] Else Local $aError[2] = [1, $sString] For $i = 1 To 30 $Toggle = Not $Toggle If $Toggle Then ; 1, 30, 3, 28 ... 27, 4, 29, 2 $sDelim &= Chr($i) Else $sDelim &= Chr(32 - $i) EndIf $iPos = StringInStr($sString, $sDelim, 1, 1, $iPos) ; смещение позволяет найти разделитель за 1 проход If Not $iPos Then ExitLoop ; если вхождение не найдено, то разделитель сформирован Next If $iPos Then Return SetError(1, 0, $aError) EndIf Switch $sIncludeMatch Case 0 $sReplace = $sDelim Case 1 $sReplace = "$0" & $sDelim Case 2 $sReplace = $sDelim & "$0" EndSwitch $sSplit = StringRegExpReplace($sString, $sPattern, $sReplace, $iCount) If @error Then Return SetError(2, @extended, $aError) If Not @extended Then Return SetError(3, 0, $aError) If $flag Then $flag = 2 Return StringSplit($sSplit, $sDelim, 1 + $flag) EndFunc ;==>_StringSplitRegExp #include <Array.au3> ; $sString = 'wd12kh4nb5016vg456yu' ; $Array = _StringSplitRegExp($sString, '\d+') ; _ArrayDisplay($Array, 'Array') $sString = '<i>Height</i> <b>15</b> <i>Width</i> <b>22</b>' $Array = _StringSplitRegExp($sString, '(?:\h*</?[ib]>\h*)+') If @error Then MsgBox(0, '', '@error = ' & @error) Else _ArrayDisplay($Array, 'Array') EndIf ; #FUNCTION# ;================================================================================= ; Name...........: _StringSplitRegExp ; Description ...: Split a string according to a regular expression. ; Syntax.........: _StringSplitRegExp($sString, $sPattern) ; Parameters ....: $sString - String: String to split. ; $sPattern - String: Regular expression to split on. ; Return values .: Success - Array ; Failure - sets @error: ; |1 - No match ; |2 - Wrong template ; |3 - The template is not provided excluding groups ; Author ........: AZJIO ; Remarks .......: ; ============================================================================================ ; Имя функции ...: _StringSplitRegExp ; Описание ........: Разделяет строки с помощью регулярного выражения ; Синтаксис.......: _StringSplitRegExp($sString, $sPattern) ; Параметры: ; $sString - Строка для деления на части ; $sPattern - Регулярное выражение определяющая строку, которая будет разделителем ; Возвращаемое значение: Успешно - Массив строк ; Неудачно - Устанавливает @error: ; |1 - Нет совпадений ; |2 - Неправильный шаблон ; |3 - В шаблоне не обеспечено исключение групп ; Автор ..........: AZJIO ; Примечания ..: Особенность такого подхода - все группы в патерне должны быть исключены из поиска методом ?: ; ============================================================================================ Func _StringSplitRegExp($sString, $sPattern) If StringRegExp(StringRegExpReplace($sPattern, '\\.', ''), '\((?!\?(?:<!|<=|=|!|:|>))') Then Return SetError(3) Local $aSplit = StringRegExp($sString, '(?s)(.*?)(?:' & $sPattern & '|\z)', 3) ; Local $aSplit = StringRegExp($sString, '(?s)(.*?' & $sPattern & '|.*?\z)', 3) If @error Then Return SetError(@error) If UBound($aSplit) > 1 Then ReDim $aSplit[UBound($aSplit)-1] Return $aSplit EndFunc ;==>_StringSplitRegExp1 point
-
Create a non-capture group of "Un" and check for AdlibRegister or AdLibUnRegister. Notice the placement of Un. The ? at the end means it might not exist, which is when it would find AdlibRegister. Negative lookbehind. If behind Call is a word character e.g. l, then fail because it's not Call, but instead something like DllCall. I'm not typical nor conventional. You should know this by now.1 point
-
Is AutoIT perfect?
matwachich reacted to water for a topic
I don 't think so. Just see what women make of any language as soon as they talk about fashion, George Clooney or other women1 point -
ozmike, I can't see your idea working. Sorry.1 point
-
I have found a way of putting my own Code128 codebars inside the created pdf's without inserting them as an image. All credits go for andybiochem for his Code128 Generator example: This is andybiochem's code: ;Code 128 Barcode Generator - Andy M 2008 #include [color=#000000][font=Consolas, 'Courier New', Courier, 'Nimbus Mono L', monospace][size=2][background=rgb(248, 248, 248)]<array.au3>[/background][/size][/font][/color] #include [color=#000000][font=Consolas, 'Courier New', Courier, 'Nimbus Mono L', monospace][size=2][background=rgb(248, 248, 248)]<file.au3>[/background][/size][/font][/color] Opt("GUIOnEventMode", 1) ;************************************************************************************* ; Declare Vars ;************************************************************************************* Global $array[104] Global $CodeArray Global $data Global $L[1] ;************************************************************************************* ; Assign Code 128 Pattern array ;************************************************************************************* ; Items are "[Value]¬[Bcode]¬[Ccode]¬[1/0 Pattern]" $array[1] = "0¬ ¬00¬11011001100" $array[2] = "1¬!¬01¬11001101100" $array[3] = '2¬"¬02¬11001100110' $array[4] = "3¬#¬03¬10010011000" $array[5] = "4¬$¬04¬10010001100" $array[6] = "5¬%¬05¬10001001100" $array[7] = "6¬&¬06¬10011001000" $array[8] = "7¬'¬07¬10011000100" $array[9] = "8¬(¬08¬10001100100" $array[10] = "9¬)¬09¬11001001000" $array[11] = "10¬*¬10¬11001000100" $array[12] = "11¬+¬11¬11000100100" $array[13] = "12¬,¬12¬10110011100" $array[14] = "13¬-¬13¬10011011100" $array[15] = "14¬.¬14¬10011001110" $array[16] = "15¬/¬15¬10111001100" $array[17] = "16¬0¬16¬10011101100" $array[18] = "17¬1¬17¬10011100110" $array[19] = "18¬2¬18¬11001110010" $array[20] = "19¬3¬19¬11001011100" $array[21] = "20¬4¬20¬11001001110" $array[22] = "21¬5¬21¬11011100100" $array[23] = "22¬6¬22¬11001110100" $array[24] = "23¬7¬23¬11101101110" $array[25] = "24¬8¬24¬11101001100" $array[26] = "25¬9¬25¬11100101100" $array[27] = "26¬:¬26¬11100100110" $array[28] = "27¬;¬27¬11101100100" $array[29] = "28¬<¬28¬11100110100" $array[30] = "29¬=¬29¬11100110010" $array[31] = "30¬>¬30¬11011011000" $array[32] = "31¬?¬31¬11011000110" $array[33] = "32¬@¬32¬11000110110" $array[34] = "33¬A¬33¬10100011000" $array[35] = "34¬B¬34¬10001011000" $array[36] = "35¬C¬35¬10001000110" $array[37] = "36¬D¬36¬10110001000" $array[38] = "37¬E¬37¬10001101000" $array[39] = "38¬F¬38¬10001100010" $array[40] = "39¬G¬39¬11010001000" $array[41] = "40¬H¬40¬11000101000" $array[42] = "41¬I¬41¬11000100010" $array[43] = "42¬J¬42¬10110111000" $array[44] = "43¬K¬43¬10110001110" $array[45] = "44¬L¬44¬10001101110" $array[46] = "45¬M¬45¬10111011000" $array[47] = "46¬N¬46¬10111000110" $array[48] = "47¬O¬47¬10001110110" $array[49] = "48¬P¬48¬11101110110" $array[50] = "49¬Q¬49¬11010001110" $array[51] = "50¬R¬50¬11000101110" $array[52] = "51¬S¬51¬11011101000" $array[53] = "52¬T¬52¬11011100010" $array[54] = "53¬U¬53¬11011101110" $array[55] = "54¬V¬54¬11101011000" $array[56] = "55¬W¬55¬11101000110" $array[57] = "56¬X¬56¬11100010110" $array[58] = "57¬Y¬57¬11101101000" $array[59] = "58¬Z¬58¬11101100010" $array[60] = "59¬[¬59¬11100011010" $array[61] = "60¬\¬60¬11101111010" $array[62] = "61¬]¬61¬11001000010" $array[63] = "62¬^¬62¬11110001010" $array[64] = "63¬_¬63¬10100110000" $array[65] = "64¬`¬64¬10100001100" $array[66] = "65¬a¬65¬10010110000" $array[67] = "66¬b¬66¬10010000110" $array[68] = "67¬c¬67¬10000101100" $array[69] = "68¬d¬68¬10000100110" $array[70] = "69¬e¬69¬10110010000" $array[71] = "70¬f¬70¬10110000100" $array[72] = "71¬g¬71¬10011010000" $array[73] = "72¬h¬72¬10011000010" $array[74] = "73¬i¬73¬10000110100" $array[75] = "74¬j¬74¬10000110010" $array[76] = "75¬k¬75¬11000010010" $array[77] = "76¬l¬76¬11001010000" $array[78] = "77¬m¬77¬11110111010" $array[79] = "78¬n¬78¬11000010100" $array[80] = "79¬o¬79¬10001111010" $array[81] = "80¬p¬80¬10100111100" $array[82] = "81¬q¬81¬10010111100" $array[83] = "82¬r¬82¬10010011110" $array[84] = "83¬s¬83¬10111100100" $array[85] = "84¬t¬84¬10011110100" $array[86] = "85¬u¬85¬10011110010" $array[87] = "86¬v¬86¬11110100100" $array[88] = "87¬w¬87¬11110010100" $array[89] = "88¬x¬88¬11110010010" $array[90] = "89¬y¬89¬11011011110" $array[91] = "90¬z¬90¬11011110110" $array[92] = "91¬{¬91¬11110110110" $array[93] = "92¬|¬92¬10101111000" $array[94] = "93¬}¬93¬10100011110" $array[95] = "94¬~¬94¬10001011110" $array[96] = "95¬del¬95¬10111101000" $array[97] = "96¬Fnc3¬96¬10111100010" $array[98] = "97¬Fnc2¬97¬11110101000" $array[99] = "98¬Shift¬98¬11110100010" $array[100] = "99¬Code C¬99¬10111011110" $array[101] = "100¬Fnc 4¬Code B¬10111101110" $array[102] = "101¬Code A¬Code A¬11101011110" $array[103] = "102¬Fnc 1¬Fnc 1¬11110101110" ;************************************************************************************* ; GUI ;************************************************************************************* GUICreate("Code 128 (B/C) Barcode Generator - AndyBiochem 2008", 613, 286) GUISetOnEvent($GUI_EVENT_CLOSE, "Close") $Input = GUICtrlCreateInput("", 8, 8, 321, 25) GUICtrlSetFont(-1,12) GUICtrlCreateButton("Generate Barcode", 344, 8, 257, 25) GUICtrlSetOnEvent(-1,"MakeBarcode") GUICtrlCreateLabel("", 8, 48, 596, 225) GUICtrlSetBkColor(-1, 0xFFFFFF) GUISetState(@SW_SHOW) ;##################################################################################### ; LOOP ;##################################################################################### While 1 Sleep(100) WEnd ;##################################################################################### ; END LOOP ;##################################################################################### Func MakeBarcode() ;************************************************************************************* ; Delete previous barcode ;************************************************************************************* for $i = 1 to (UBound($L) - 1) GUICtrlDelete($L[$i]) Next ;************************************************************************************* ; Generate Pattern ;************************************************************************************* $Barcode = IdentifyCodeSwitches(GUICtrlRead($Input)) ;************************************************************************************* ; Draw new Barcode ;************************************************************************************* Dim $L[StringLen($Barcode) + 1] $i = 1 While $i <= StringLen($barcode) $col = StringMid($barcode,$i,1) if $col = 1 Then $L[$i] = GUICtrlCreateLabel("",50 + ($i * 2),100,2,100) GUICtrlSetBkColor(-1,0x000000) Else $L[$i] = GUICtrlCreateLabel("",50 + ($i * 2),100,2,100) GUICtrlSetBkColor(-1,0xFFFFFF) EndIf $i += 1 WEnd EndFunc Func IdentifyCodeSwitches($code) ;************************************************************************************* ; Identify where code switches should be ;************************************************************************************* $i = 1 $CodeType = "B" ;always start with code type B $len = StringLen($Code) While $i <= $len Select Case $CodeType = "B" if StringRegExp(StringMid($Code,$i,6),"([0-9][0-9]){3}") = 1 Then $Code = StringMid($Code,1,$i - 1) & "¬C¬" & StringMid($Code,$i) $CodeType = "C" $i += 6 + 3 Else $CodeType = "B" $i += 1 EndIf Case $CodeType = "C" if StringRegExp(StringMid($Code,$i,2),"([0-9][0-9])") <> 1 Then $Code = StringMid($Code,1,$i - 1) & "¬B¬" & StringMid($Code,$i) $CodeType = "B" $i += 2 + 3 Else $CodeType = "C" $i += 2 EndIf EndSelect $len = StringLen($Code) WEnd ;************************************************************************************* ; Add start code B, if not already started C ;************************************************************************************* if StringMid($Code,1,3) <> "¬C¬" then $Code = "¬B¬" & $Code ;************************************************************************************* ; Split to array, re-assemble code switches ;************************************************************************************* $CodeArray = StringSplit($code,"") for $i = 1 to (UBound($CodeArray) - 3) Select case $CodeArray[$i] & $CodeArray[$i+1] & $CodeArray[$i+2] = "¬B¬" $CodeArray[$i] = "[B]" $CodeArray[$i+1] = "" $CodeArray[$i+2] = "" case $CodeArray[$i] & $CodeArray[$i+1] & $CodeArray[$i+2] = "¬C¬" $CodeArray[$i] = "[C]" $CodeArray[$i+1] = "" $CodeArray[$i+2] = "" EndSelect Next ;************************************************************************************* ; Remove empty items ;************************************************************************************* for $i = (UBound($CodeArray) - 1) to 1 step -1 if $CodeArray[$i] = "" then _ArrayDelete($CodeArray,$i) Next ;************************************************************************************* ; Concatenate C number pairs ;************************************************************************************* $i = 1 While $i <= (UBound($CodeArray) - 1) if $CodeArray[$i] = "[C]" Then $i += 1 do if $CodeArray[$i] = "" then $i += 1 Else $CodeArray[$i] &= $CodeArray[$i + 1] $CodeArray[$i + 1] = "" $i += 1 EndIf Until $i = (UBound($CodeArray) - 1) Or $CodeArray[$i] = "[B]" or $CodeArray[$i + 1] = "[B]" EndIf $i += 1 WEnd ;************************************************************************************* ; Remove empty items ;************************************************************************************* for $i = (UBound($CodeArray) - 1) to 1 step -1 if $CodeArray[$i] = "" then _ArrayDelete($CodeArray,$i) Next ;************************************************************************************* ; Replace Items with 128 Code Patterns, and mount checksum ;************************************************************************************* _ArrayDelete($CodeArray,0) ;important If $CodeArray[0] = "[B]" Then $CodeArray[0] = "11010010000" $SUM = 104 $CodeType = "[B]" Else $CodeArray[0] = "11010011100" $SUM = 105 $CodeType = "[C]" EndIf for $i = 1 to (UBound($CodeArray) - 1) if $CodeArray[$i] = "[B]" Then $CodeArray[$i] = "10111101110" $SUM += $i * 100 $CodeType = "[B]" ContinueLoop EndIf if $CodeArray[$i] = "[C]" Then $CodeArray[$i] = "10111011110" $SUM += $i * 99 $CodeType = "[C]" ContinueLoop EndIf for $j = 1 to (UBound($array) - 1) $data = StringSplit($array[$j],"¬") Select case $CodeType = "[B]" if $CodeArray[$i] == $data[2] Then $CodeArray[$i] = $data[4] $SUM += $i * $data[1] EndIf case $CodeType = "[C]" if $CodeArray[$i] == $data[3] Then $CodeArray[$i] = $data[4] $SUM += $i * $data[1] EndIf EndSelect Next Next ;************************************************************************************* ; Calculate & find checksum item ;************************************************************************************* $ChecksumItem = Mod($SUM,103) $data = StringSplit($array[$ChecksumItem + 1],"¬") _ArrayAdd($CodeArray,$data[4]) ;************************************************************************************* ; Add stop item ;************************************************************************************* _ArrayAdd($CodeArray,"1100011101011") ;************************************************************************************* ; Flatten array ;************************************************************************************* $CodeArrayString = _ArrayToString($CodeArray,"") Return $CodeArrayString EndFunc func close() ;************************************************************************************* ; Bye bye ;************************************************************************************* Exit EndFunc Notice that he draws the codebar inside a GUI code using labels: ;************************************************************************************* ; Draw new Barcode ;************************************************************************************* Dim $L[StringLen($Barcode) + 1] $i = 1 While $i <= StringLen($barcode) $col = StringMid($barcode,$i,1) if $col = 1 Then $L[$i] = GUICtrlCreateLabel("",50 + ($i * 2),100,2,100) GUICtrlSetBkColor(-1,0x000000) Else $L[$i] = GUICtrlCreateLabel("",50 + ($i * 2),100,2,100) GUICtrlSetBkColor(-1,0xFFFFFF) EndIf $i += 1 WEnd EndFunc If we want to insert the barcode inside our pdf we can create lines instead of colored labels. Here is a working example: #include <MPDF_UDF.au3> #include <array.au3> #include <file.au3> ;************************************************************************************* ; Declare Vars ;************************************************************************************* Global $array[104] Global $CodeArray Global $data Global $L[1] ;************************************************************************************* ; Assign Code 128 Pattern array ;************************************************************************************* ; Items are "[Value]¬[Bcode]¬[Ccode]¬[1/0 Pattern]" $array[1] = "0¬ ¬00¬11011001100" $array[2] = "1¬!¬01¬11001101100" $array[3] = '2¬"¬02¬11001100110' $array[4] = "3¬#¬03¬10010011000" $array[5] = "4¬$¬04¬10010001100" $array[6] = "5¬%¬05¬10001001100" $array[7] = "6¬&¬06¬10011001000" $array[8] = "7¬'¬07¬10011000100" $array[9] = "8¬(¬08¬10001100100" $array[10] = "9¬)¬09¬11001001000" $array[11] = "10¬*¬10¬11001000100" $array[12] = "11¬+¬11¬11000100100" $array[13] = "12¬,¬12¬10110011100" $array[14] = "13¬-¬13¬10011011100" $array[15] = "14¬.¬14¬10011001110" $array[16] = "15¬/¬15¬10111001100" $array[17] = "16¬0¬16¬10011101100" $array[18] = "17¬1¬17¬10011100110" $array[19] = "18¬2¬18¬11001110010" $array[20] = "19¬3¬19¬11001011100" $array[21] = "20¬4¬20¬11001001110" $array[22] = "21¬5¬21¬11011100100" $array[23] = "22¬6¬22¬11001110100" $array[24] = "23¬7¬23¬11101101110" $array[25] = "24¬8¬24¬11101001100" $array[26] = "25¬9¬25¬11100101100" $array[27] = "26¬:¬26¬11100100110" $array[28] = "27¬;¬27¬11101100100" $array[29] = "28¬<¬28¬11100110100" $array[30] = "29¬=¬29¬11100110010" $array[31] = "30¬>¬30¬11011011000" $array[32] = "31¬?¬31¬11011000110" $array[33] = "32¬@¬32¬11000110110" $array[34] = "33¬A¬33¬10100011000" $array[35] = "34¬B¬34¬10001011000" $array[36] = "35¬C¬35¬10001000110" $array[37] = "36¬D¬36¬10110001000" $array[38] = "37¬E¬37¬10001101000" $array[39] = "38¬F¬38¬10001100010" $array[40] = "39¬G¬39¬11010001000" $array[41] = "40¬H¬40¬11000101000" $array[42] = "41¬I¬41¬11000100010" $array[43] = "42¬J¬42¬10110111000" $array[44] = "43¬K¬43¬10110001110" $array[45] = "44¬L¬44¬10001101110" $array[46] = "45¬M¬45¬10111011000" $array[47] = "46¬N¬46¬10111000110" $array[48] = "47¬O¬47¬10001110110" $array[49] = "48¬P¬48¬11101110110" $array[50] = "49¬Q¬49¬11010001110" $array[51] = "50¬R¬50¬11000101110" $array[52] = "51¬S¬51¬11011101000" $array[53] = "52¬T¬52¬11011100010" $array[54] = "53¬U¬53¬11011101110" $array[55] = "54¬V¬54¬11101011000" $array[56] = "55¬W¬55¬11101000110" $array[57] = "56¬X¬56¬11100010110" $array[58] = "57¬Y¬57¬11101101000" $array[59] = "58¬Z¬58¬11101100010" $array[60] = "59¬[¬59¬11100011010" $array[61] = "60¬\¬60¬11101111010" $array[62] = "61¬]¬61¬11001000010" $array[63] = "62¬^¬62¬11110001010" $array[64] = "63¬_¬63¬10100110000" $array[65] = "64¬`¬64¬10100001100" $array[66] = "65¬a¬65¬10010110000" $array[67] = "66¬b¬66¬10010000110" $array[68] = "67¬c¬67¬10000101100" $array[69] = "68¬d¬68¬10000100110" $array[70] = "69¬e¬69¬10110010000" $array[71] = "70¬f¬70¬10110000100" $array[72] = "71¬g¬71¬10011010000" $array[73] = "72¬h¬72¬10011000010" $array[74] = "73¬i¬73¬10000110100" $array[75] = "74¬j¬74¬10000110010" $array[76] = "75¬k¬75¬11000010010" $array[77] = "76¬l¬76¬11001010000" $array[78] = "77¬m¬77¬11110111010" $array[79] = "78¬n¬78¬11000010100" $array[80] = "79¬o¬79¬10001111010" $array[81] = "80¬p¬80¬10100111100" $array[82] = "81¬q¬81¬10010111100" $array[83] = "82¬r¬82¬10010011110" $array[84] = "83¬s¬83¬10111100100" $array[85] = "84¬t¬84¬10011110100" $array[86] = "85¬u¬85¬10011110010" $array[87] = "86¬v¬86¬11110100100" $array[88] = "87¬w¬87¬11110010100" $array[89] = "88¬x¬88¬11110010010" $array[90] = "89¬y¬89¬11011011110" $array[91] = "90¬z¬90¬11011110110" $array[92] = "91¬{¬91¬11110110110" $array[93] = "92¬|¬92¬10101111000" $array[94] = "93¬}¬93¬10100011110" $array[95] = "94¬~¬94¬10001011110" $array[96] = "95¬del¬95¬10111101000" $array[97] = "96¬Fnc3¬96¬10111100010" $array[98] = "97¬Fnc2¬97¬11110101000" $array[99] = "98¬Shift¬98¬11110100010" $array[100] = "99¬Code C¬99¬10111011110" $array[101] = "100¬Fnc 4¬Code B¬10111101110" $array[102] = "101¬Code A¬Code A¬11101011110" $array[103] = "102¬Fnc 1¬Fnc 1¬11110101110" Local $Inputdata = InputBox("Codebar Example", "Type the data to be codified into the codebar") If @error = 1 Then Exit Else Global $Barcodedata = IdentifyCodeSwitches($Inputdata) _SetTitle("Codebar example") _SetUnit($PDF_UNIT_CM) _SetPaperSize("A4") _SetZoomMode($PDF_ZOOM_FULLPAGE) _SetOrientation($PDF_ORIENTATION_PORTRAIT) _SetLayoutMode($PDF_LAYOUT_CONTINOUS) _OpenAfter(True) _InitPDF(@ScriptDir & "\Codebar Example.pdf") _BeginPage() Dim $L[StringLen($Barcodedata) + 1] $i = 1 Local $pixelcm = 0.06 ; here we define the width of the lines that form the codebar. Adjust depending on the space that you'll have While $i <= StringLen($Barcodedata) $col = StringMid($Barcodedata, $i, 1) If $col = 1 Then $L[$i] = _DrawLine(3 + ($i * $pixelcm), 29, 3 + ($i * $pixelcm), 27, $pixelcm, $PDF_STYLE_STROKED, $pixelcm, 0x000000) ; adjust the position of the lines depending on where do you need the codebar in the page. Else $L[$i] = _DrawLine(3 + ($i * $pixelcm), 29, 3 + ($i * $pixelcm), 27, $pixelcm, $PDF_STYLE_STROKED, $pixelcm, 0xffFFFF) EndIf $i += 1 Sleep(30) WEnd _EndPage() _ClosePDFFile() Exit EndIf Func IdentifyCodeSwitches($code) ;************************************************************************************* ; Identify where code switches should be ;************************************************************************************* $i = 1 $CodeType = "B" ;always start with code type B $len = StringLen($code) While $i <= $len Sleep(20) Select Case $CodeType = "B" If StringRegExp(StringMid($code, $i, 6), "([0-9][0-9]){3}") = 1 Then $code = StringMid($code, 1, $i - 1) & "¬C¬" & StringMid($code, $i) $CodeType = "C" $i += 6 + 3 Else $CodeType = "B" $i += 1 EndIf Case $CodeType = "C" If StringRegExp(StringMid($code, $i, 2), "([0-9][0-9])") <> 1 Then $code = StringMid($code, 1, $i - 1) & "¬B¬" & StringMid($code, $i) $CodeType = "B" $i += 2 + 3 Else $CodeType = "C" $i += 2 EndIf EndSelect $len = StringLen($code) WEnd ;************************************************************************************* ; Add start code B, if not already started C ;************************************************************************************* If StringMid($code, 1, 3) <> "¬C¬" Then $code = "¬B¬" & $code ;************************************************************************************* ; Split to array, re-assemble code switches ;************************************************************************************* $CodeArray = StringSplit($code, "") For $i = 1 To (UBound($CodeArray) - 3) Select Case $CodeArray[$i] & $CodeArray[$i + 1] & $CodeArray[$i + 2] = "¬B¬" $CodeArray[$i] = "[B]" $CodeArray[$i + 1] = "" $CodeArray[$i + 2] = "" Case $CodeArray[$i] & $CodeArray[$i + 1] & $CodeArray[$i + 2] = "¬C¬" $CodeArray[$i] = "[C]" $CodeArray[$i + 1] = "" $CodeArray[$i + 2] = "" EndSelect Next ;************************************************************************************* ; Remove empty items ;************************************************************************************* For $i = (UBound($CodeArray) - 1) To 1 Step -1 If $CodeArray[$i] = "" Then _ArrayDelete($CodeArray, $i) Next ;************************************************************************************* ; Concatenate C number pairs ;************************************************************************************* $i = 1 While $i <= (UBound($CodeArray) - 1) If $CodeArray[$i] = "[C]" Then $i += 1 Do If $CodeArray[$i] = "" Then $i += 1 Else $CodeArray[$i] &= $CodeArray[$i + 1] $CodeArray[$i + 1] = "" $i += 1 EndIf Until $i = (UBound($CodeArray) - 1) Or $CodeArray[$i] = "[B]" Or $CodeArray[$i + 1] = "[B]" EndIf $i += 1 WEnd ;************************************************************************************* ; Remove empty items ;************************************************************************************* For $i = (UBound($CodeArray) - 1) To 1 Step -1 If $CodeArray[$i] = "" Then _ArrayDelete($CodeArray, $i) Next ;************************************************************************************* ; Replace Items with 128 Code Patterns, and mount checksum ;************************************************************************************* _ArrayDelete($CodeArray, 0) ;important If $CodeArray[0] = "[B]" Then $CodeArray[0] = "11010010000" $SUM = 104 $CodeType = "[B]" Else $CodeArray[0] = "11010011100" $SUM = 105 $CodeType = "[C]" EndIf For $i = 1 To (UBound($CodeArray) - 1) If $CodeArray[$i] = "[B]" Then $CodeArray[$i] = "10111101110" $SUM += $i * 100 $CodeType = "[B]" ContinueLoop EndIf If $CodeArray[$i] = "[C]" Then $CodeArray[$i] = "10111011110" $SUM += $i * 99 $CodeType = "[C]" ContinueLoop EndIf For $j = 1 To (UBound($array) - 1) $data = StringSplit($array[$j], "¬") Select Case $CodeType = "[B]" If $CodeArray[$i] == $data[2] Then $CodeArray[$i] = $data[4] $SUM += $i * $data[1] EndIf Case $CodeType = "[C]" If $CodeArray[$i] == $data[3] Then $CodeArray[$i] = $data[4] $SUM += $i * $data[1] EndIf EndSelect Next Next ;************************************************************************************* ; Calculate & find checksum item ;************************************************************************************* $ChecksumItem = Mod($SUM, 103) $data = StringSplit($array[$ChecksumItem + 1], "¬") _ArrayAdd($CodeArray, $data[4]) ;************************************************************************************* ; Add stop item ;************************************************************************************* _ArrayAdd($CodeArray, "1100011101011") ;************************************************************************************* ; Flatten array ;************************************************************************************* $CodeArrayString = _ArrayToString($CodeArray, "") Return $CodeArrayString EndFunc ;==>IdentifyCodeSwitches As said above all credits go for andybiochem. Apologizes for my coding skills, I know that my code looks awful and can be writted better. It works for me and I thought that someone could find interesting to have a code bar created directly in the pdf (you can zoom it as much as you want, it will always look great). You can check your created codebars with websites like: http://www.onlinebarcodereader.com/ Greets from Barcelona1 point
-
Every SQL engine is special and to complicate matters more, there are way too many SQL "standards" to choose from. For SQLite, a primary key having INTEGER type becomes an alias to the implicit rowid column that exists if you don't specify an INTEGER PRIMARY KEY explicitely. Making that INT PRIMARY KEY spoils this magical behavior and the implicit rowid is created as a distinct column and index. That's how SQLite works and this particular detail is unique to SQLite.1 point