PowerBuilder Generate a UUID
generate a version 4 UUID RFC 4122. Add four hyphen “-” characters to obtain blocks of 8, 4, 4, 4 and 12 hex digits. Output the resulting 36-character string “XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX”.
Code Example: Create nvo_uuid from nonvisualobject
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | forward global type nvo_uuid from nonvisualobject end type type uuid from structure within nvo_uuid end type type s_uuid from structure within nvo_uuid end type end forward type uuid from structure unsignedlong data1 integer data2 integer data3 blob data4 end type type s_uuid from structure unsignedlong data1 unsignedinteger data2 unsignedinteger data3 unsignedinteger data4[4] end type global type nvo_uuid from nonvisualobject autoinstantiate end type type prototypes Function Long UuidCreateSequential ( Ref UUID UUID ) Library "rpcrt4.dll" Function Long UuidToString ( Ref UUID UUID, Ref ULong StringUuid ) Library "rpcrt4.dll" Alias For "UuidToStringW" Function Long RpcStringFree ( Ref ULong pString ) Library "rpcrt4.dll" Alias For "RpcStringFreeW" Subroutine CopyMemory ( Ref String Destination, ULong Source, Long Length ) Library "kernel32.dll" Alias For "RtlMoveMemory" Function Long uuidCreate(Ref s_UUID astr_uuid) Library "Rpcrt4.dll" Alias For "UuidCreate" end prototypes forward prototypes public function String of_hex (unsignedlong aul_decimal) public function string of_generate_uuid2 (string as_type, string as_case) public function string of_generate_uuid (string as_case) public function string of_generate_uuid_time () end prototypes public function String of_hex (unsignedlong aul_decimal);String ls_hex Character lch_hex[0 To 15] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'} // Check parameters If IsNull(aul_decimal) Then SetNull(ls_hex) Return ls_hex End If Do ls_hex = lch_hex[Mod(aul_decimal, 16)] + ls_hex aul_decimal /= 16 Loop Until aul_decimal = 0 Return ls_hex end function public function string of_generate_uuid2 (string as_type, string as_case);//==================================================================== // Function: nvo_uuid.of_generate_uuid2() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // string as_type // string as_case //-------------------------------------------------------------------- // Returns: string //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2021/05/18 //-------------------------------------------------------------------- // Usage: nvo_uuid.of_generate_uuid2 ( string as_type, string as_case ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Long ll_rc s_uuid lstr_uuid String ls_guid = "" Constant Long RPC_S_OK = 0 Constant Long RPC_S_UUID_LOCAL_ONLY = 1824 Constant Long RPC_S_UUID_NO_ADDRESS = 1739 ll_rc = uuidCreate(lstr_uuid) // returns // RPC_S_OK - The call succeeded. // RPC_S_UUID_LOCAL_ONLY - The UUID is guaranteed to be unique to this computer only. // RPC_S_UUID_NO_ADDRESS - Cannot get Ethernet/token-ring hardware address for this computer. If ll_rc <> RPC_S_OK Then SetNull(ls_guid) // MessageBox("", "uuid create not ok ?!?") Else If as_type = 'F' Then ls_guid = Right("00000000" + of_hex(lstr_uuid.data1), 8) ls_guid += "-" + Right("0000" + of_hex(lstr_uuid.data2), 4) ls_guid += "-" + Right("0000" + of_hex(lstr_uuid.data3), 4) ls_guid += "-" + Right("0000" + of_hex(lstr_uuid.data4[1]), 4) ls_guid += "-" + Right("0000" + of_hex(lstr_uuid.data4[2]), 4) + Right("0000" + of_hex(lstr_uuid.data4[3]), 4) + Right("0000" + of_hex(lstr_uuid.data4[4]), 4) If Upper(Trim(as_case))= "U" Then ls_guid = Upper(ls_guid) ElseIf Upper(Trim(as_case))= "L" Then ls_guid = lower(ls_guid) End If ElseIf as_type = 'R' Then ls_guid = Right("00000000" + of_hex(lstr_uuid.data1), 8) ls_guid += Right("0000" + of_hex(lstr_uuid.data2), 4) ls_guid += Right("0000" + of_hex(lstr_uuid.data3), 4) ls_guid += Right("0000" + of_hex(lstr_uuid.data4[1]), 4) ls_guid += Right("0000" + of_hex(lstr_uuid.data4[2]), 4) + Right("0000" + of_hex(lstr_uuid.data4[3]), 4) + Right("0000" + of_hex(lstr_uuid.data4[4]), 4) If Upper(Trim(as_case))= "U" Then ls_guid = Upper(ls_guid) ElseIf Upper(Trim(as_case))= "L" Then ls_guid = lower(ls_guid) End If End If End If Return ls_guid end function public function string of_generate_uuid (string as_case);//==================================================================== // Function: nvo_uuid.of_generate_uuid() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // string as_case //-------------------------------------------------------------------- // Returns: string //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2021/05/18 //-------------------------------------------------------------------- // Usage: nvo_uuid.of_generate_uuid ( string as_case ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== UUID lstr_UUID Constant Long RPC_S_OK = 0 Constant Long SZ_UUID_LEN = 36 ULong lul_ptrUuid String ls_Uuid lstr_UUID.Data4 = Blob(Space(8), EncodingAnsi!) ls_Uuid = Space(SZ_UUID_LEN + 2) Try If UuidCreateSequential(lstr_UUID) = RPC_S_OK Then If UuidToString(lstr_UUID, lul_ptrUuid) = RPC_S_OK Then CopyMemory(ls_Uuid, lul_ptrUuid, SZ_UUID_LEN*2) RpcStringFree(lul_ptrUuid) End If End If Catch (RuntimeError rte) PopulateError(rte.Number, rte.Text) End Try If Upper(Trim(as_case)) = "U" Then ls_Uuid = Upper(Trim(ls_Uuid)) ElseIf Upper(Trim(as_case)) = "L" Then ls_Uuid = Lower(Trim(ls_Uuid)) End If Return ls_Uuid end function public function string of_generate_uuid_time ();Return "ABC"+String(Now(),"yyyymmddhhmmssms")+String(Rand(1000)) end function on nvo_uuid.create call super::create TriggerEvent( this, "constructor" ) end on on nvo_uuid.destroy TriggerEvent( this, "destructor" ) call super::destroy end on |
Window Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | forward global type w_main from window end type type cbx_hyphen from checkbox within w_main end type type cbx_case from checkbox within w_main end type type rb_mt2 from radiobutton within w_main end type type rb_mt1 from radiobutton within w_main end type type st_1 from statictext within w_main end type type sle_uuid from singlelineedit within w_main end type type cb_generateuuid from commandbutton within w_main end type end forward global type w_main from window integer width = 2757 integer height = 496 boolean titlebar = true string title = "Generate UUID" boolean controlmenu = true boolean minbox = true boolean maxbox = true boolean resizable = true long backcolor = 67108864 string icon = "AppIcon!" boolean center = true cbx_hyphen cbx_hyphen cbx_case cbx_case rb_mt2 rb_mt2 rb_mt1 rb_mt1 st_1 st_1 sle_uuid sle_uuid cb_generateuuid cb_generateuuid end type global w_main w_main type prototypes end prototypes on w_main.create this.cbx_hyphen=create cbx_hyphen this.cbx_case=create cbx_case this.rb_mt2=create rb_mt2 this.rb_mt1=create rb_mt1 this.st_1=create st_1 this.sle_uuid=create sle_uuid this.cb_generateuuid=create cb_generateuuid this.Control[]={this.cbx_hyphen,& this.cbx_case,& this.rb_mt2,& this.rb_mt1,& this.st_1,& this.sle_uuid,& this.cb_generateuuid} end on on w_main.destroy destroy(this.cbx_hyphen) destroy(this.cbx_case) destroy(this.rb_mt2) destroy(this.rb_mt1) destroy(this.st_1) destroy(this.sle_uuid) destroy(this.cb_generateuuid) end on type cbx_hyphen from checkbox within w_main integer x = 1865 integer y = 44 integer width = 329 integer height = 80 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 boolean enabled = false string text = "hyphen" boolean checked = true end type type cbx_case from checkbox within w_main integer x = 2231 integer y = 44 integer width = 402 integer height = 80 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "Upper Case" boolean checked = true boolean threestate = true end type event clicked;If cbx_case.Checked Then If cbx_case.ThirdState Then This.Text = "Lower Case" Else This.Text = "Upper Case" End If Else This.Text = "Nomal" End If end event type rb_mt2 from radiobutton within w_main integer x = 1170 integer y = 44 integer width = 366 integer height = 80 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "Method 2" end type event clicked;cbx_hyphen.enabled = this.checked end event type rb_mt1 from radiobutton within w_main integer x = 768 integer y = 44 integer width = 366 integer height = 80 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "Method 1" boolean checked = true end type event clicked;cbx_hyphen.enabled = rb_mt2.checked end event type st_1 from statictext within w_main integer x = 30 integer y = 204 integer width = 183 integer height = 64 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "UUID:" alignment alignment = right! boolean focusrectangle = false end type type sle_uuid from singlelineedit within w_main integer x = 219 integer y = 192 integer width = 2450 integer height = 96 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 borderstyle borderstyle = stylelowered! end type type cb_generateuuid from commandbutton within w_main integer x = 219 integer y = 32 integer width = 489 integer height = 112 integer taborder = 10 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Generate UUID" end type event clicked;nvo_uuid lnvo_uuid String ls_case, ls_uuid If cbx_case.Checked Then If cbx_case.ThirdState Then ls_case = "L" Else ls_case = "U" End If Else ls_case = "N" End If If rb_mt1.Checked Then ls_uuid = lnvo_uuid.of_generate_uuid(ls_case ) ElseIf rb_mt2.Checked Then If cbx_hyphen.Checked Then ls_uuid = lnvo_uuid.of_generate_uuid2("F", ls_case ) Else ls_uuid = lnvo_uuid.of_generate_uuid2("R", ls_case ) End If End If sle_uuid.Text = ls_uuid end event |
Find Projects On Github click here
Good Luck!