I am new to PowerBuilder.
I am using PB 11, can anyone give me very small PB example
which demonstrate BlobMid() , BlobEdit() ( not event) of
PowerBuilder.
Thanks
Jenny
blob lblb_result
string ls_hex = "0123456789ABCDEF", ls_temp
long ll_index
byte lbt_temp
if mod(len(as_input), 2) = 1 then
as_input = "0" + as_input
end if
// The working blob is created with 1 additional byte,
// because when BlobEdit function is called for the last byte
// of the blob, it returns NULL (position at which the next data
// can be copied - not enough space) and doesn't perform
// the operation for the last byte of the blob!
lblb_result = Blob(space(len(as_input) / 2 + 1), EncodingANSI!)
for ll_index = 1 to len(as_input) step 2
// Get next byte from the string
ls_temp = Upper(mid(as_input, ll_index, 2))
lbt_temp = 16 * (pos(ls_hex, mid(ls_temp, 1, 1)) - 1) + pos(ls_hex,
mid(ls_temp, 2, 1)) - 1
// Put the byte into the blob
BlobEdit(lblb_result, (ll_index + 1)/ 2, lbt_temp)
next
lblb_result = BlobMid(lblb_result, 1, len(lblb_result) - 1)
return lblb_result
Is this enough? If not, have you looked at the examples in the help for
these functions?
Regards,
Ivaylo
<Jenny> wrote in message news:4b151120.490...@sybase.com...
-----------------------Code ---------------------------
blob{100} bb
long pos1, pos2
string test_day
date test_date
test_date = Today()
test_day = DayName(test_date)
// Store data in the blob
pos1 = BlobEdit( bb, 1, string(test_date))
messagebox("Position for Date", string(pos1))
pos2 = BlobEdit( bb, pos1, test_day )
// Extract the status stored in bb and display it
messagebox("Position for Day", string(pos2))
messagebox("I am expecting result should be ‘Date +
Day’, why I am getting only Date?", String( BlobMid(bb,
1, len(bb))))
string ls_s
ls_s = String( BlobMid(bb, pos1, pos2 - pos1))
messagebox("ls_s", ls_s)
-----------------------Code ---------------------------
So if you try to convert the entire blob contents back to string, the
conversion will stop on the first null terminating character thus returning
just the "Date" part. So you would ask for the solutions and here they are:
1) A general solution to BLOB-related problems is to have a convenient way
to observe what's really happening with their values by saving the contents
of a blob variable to a binary file. Here is a sample script (sorry, no
error-handling!) which you can add somewhere at the end or anywhere between
the statements of your script to make such export:
integer li_FileNum
li_FileNum = FileOpen("test.blb", StreamMode!, Write!, LockReadWrite!,
Replace!)
FileWriteEx(li_FileNum, bb)
FileClose(li_FileNum)
Run your script, open the binary file in any hex viewer/editor and ....
there you would see...
2) Of course, now as you know the problem, first workaround would be to
decrease pos1 by 2 in the second call like this:
pos2 = BlobEdit( bb, pos1 - 2, test_day )
3) second workaround (which I prefer) would be to concatenate the two
strings and put their concatenation in the blob with just one BlobEdit:
pos1 = BlobEdit(bb, 1, string(test_date) + test_day)
... or even not using BlobEdit, but a direct Blob() call:
bb = Blob(string(test_date) + test_day)
So always have in mind that blob-->string conversion would stop on the 00 00
(null) terminating sequence.
BTW, this "String(BlobMid(bb,1, len(bb)))" can be just "String(bb)".
Regards,
Ivaylo
<Jenny> wrote in message news:4b164ef0.687...@sybase.com...
How I can achieve both the things…
Thanks,
Jenny
Also, when you're observing the byte contents of the blob take into account
the 2-byte representation UTF16LE! which is the default of PB10+.
If you post a newer code here, I would probably help you further with what
you're trying to achieve, but you should describe the exact problem.
Regards,
Ivaylo
<Jenny> wrote in message news:4b166ec9.6d5...@sybase.com...
1. when i use string value in BlobEdit() then it is
overwriting the old sting value
2. When I am trying to get the date value my BlobMid() then
I am getting garbage, can to tell me
How I can achieve both the things.
blob{100} bb
long pos1, pos2
string test_day
date test_date
test_date = Today()
test_day = DayName(test_date)
// Store data in the blob
// NOTICE THE CHANGE HERE
pos1 = BlobEdit( bb, 1, blob(string(test_date)))
messagebox("Position for Date", string(pos1))
pos2 = BlobEdit( bb, pos1, test_day )
// Extract the status stored in bb and display it
messagebox("Position for Day", string(pos2))
messagebox("I am expecting result should be 'Date Day', why I am getting
only Date?", &
String (BlobMid (bb, 1, len(bb))))
return 1
When using BlobEdit the blob variable must already contain data that you are
changing. It is not for initial population of the blob. Try this:
Blob lblob_data
ULong lul_rtn
String ls_data
ls_data = "something"
lblob_data = Blob(Space(100))
lul_rtn = BlobEdit(lblob_data, 10, ls_data)
This example will first populate the blob variable with 100 spaces. Then it
takes the value in ls_data and updates the blob starting with position 10.
<Jenny> wrote in message news:4b166ec9.6d5...@sybase.com...
1. when i use string value in BlobEdit() then it is
overwriting the old sting value
2. When I am trying to get the date value my BlobMid() then
I am getting garbage, can to tell me
How I can achieve both the things.
Are you just messing around trying to learn PowerBuilder or does this relate
to a specific business requirement?
It is usually a good idea to explain why you want to do something. Someone
may come up with a completely different way of doing something. A narrowly
worded question wouldn't get that response.
<Jenny> wrote in message news:4b164f7b.688...@sybase.com...
On Dec 4, 2:09 pm, "Roland Smith [TeamSybase]"
<topwiz.smith_at_comcast_dot_net> wrote:
> Why are you combining strings into a blob in the first place?
>
> When using BlobEdit the blob variable must already contain data that you are
> changing. It is not for initial population of the blob. Try this:
>
> Blob lblob_data
> ULong lul_rtn
> String ls_data
>
> ls_data = "something"
>
> lblob_data = Blob(Space(100))
>
> lul_rtn = BlobEdit(lblob_data, 10, ls_data)
>
> This example will first populate the blob variable with 100 spaces. Then it
> takes the value in ls_data and updates the blob starting with position 10.
>
> <Jenny> wrote in messagenews:4b166ec9.6d5...@sybase.com...
How about when you first initialize the blob. Is there something faster than
Blob(Space(x))?
"Jeremy Lakeman" <jeremy....@gmail.com> wrote in message
news:230610f0-63fb-438c...@r24g2000prf.googlegroups.com...
;)
Useful if you always use blobs that are the same size.
On Dec 6, 12:04 pm, "Roland Smith [TeamSybase]"
<topwiz.smith_at_comcast_dot_net> wrote:
> That is a good tip.
>
> How about when you first initialize the blob. Is there something faster than
> Blob(Space(x))?
>
> "Jeremy Lakeman" <jeremy.lake...@gmail.com> wrote in message
How I can drive the formula for date, datetime , int, long ,
double etc.. ?
Can anyone tell me what is generic formula for
Blob
Integer or Int
Boolean
LongLong
Byte
Long
Char or character
Real
Date
String
DateTime
Time
Decimal or Dec
UnsignedInteger, UnsignedInt, or UInt
Double
UnsignedLong or ULong
-------------------Code-------------------------------------------
Blob bb
Whatis formula to get return value = BlobEdit( bb, 1,
string_variable)
Whatis formula to get return value = BlobEdit( bb, 1, int_
variable)
Etc…
-------------------Code-------------------------------------------
> > , 1, len(bb))))
I did - a working example based on the OP's original code - in response to
the next post on the same topic by OP. It will help if you read the
documentation very closely and pay special attention to the information
about strings and encoding. If you don't have a good handle on the
differences between unicode and ansi strings, then you should investigate
that aspect first.