PC SOFT
DEPOT EN LIGNE
POUR WINDEVWEBDEV ET WINDEV MOBILE

WD Different types of strings
Publié par Boller
dans la catégorie Outils
Nouveautés



Description
WD Different types of strings

// Syntax:
//UPD ()
//
// This procedure is used to update all the controls found in the window
// 1 - The edit control containing the display of the Unicode string
// 2 - The edit control containing the display of the Fixed string
// 3 - The edit control containing the display of the ASCIIZ string
// 4 - The edit control containing the display of the Pascal string
// 5 - The caption used to find out whether the selected image is a GIF image or not
//
//
PROCEDURE UPD()


// --------------------------------------------
// ---------- LOCAL VARIABLES ---------------
// --------------------------------------------

// Variable used to display the UNICODE string

sMyUnicodeString is string UNICODE // Declare a UNICODE string
i is int // Counter for the loop (this variable is used for the display only)

// Variable used to display the fixed string
sMyFixedString is string on 50 // Declare the Fixed string on 50
nLengthToComplete is int // Counter used to find out the size to complete (this variable is used for the display only)




// --------------------------------------------
// ---------- 1 - UNICODE string --------------
// --------------------------------------------


// Conversion from ANSI type (TXT_SIMPLE) to UNICODE type (sMyUnicodeString)
sMyUnicodeString = AnsiToUnicode(TXT_SIMPLE)

// Build the UNICODE string
// CAUTION: This part of code is valid to view a UNICODE string only
// Reset the control of UNICODE text
TXT_UNICODE =""
nStringSize is int
nStringSize = Length(sMyUnicodeString)
// Browse the string to retrieve all the characters
FOR i = 1 TO nStringSize

// Convert the string into ANSI (to be able to view it) and add the character 0
// that separates all the characters whose ASCII code is less than 255
TXT_UNICODE +=UnicodeToAnsi(sMyUnicodeString[[i]]) + "<0>"

END

// Add the character 0 at the end of the string
// Indeed, as a UNICODE string contains characters 0 between each character (for the characters of the Latin charset),
// We cannot base on this character to mark the end of the string (as the ASCIIZ strings for instance)
// That's the reason why the end marker of a UNICODE string is made of two consecutive characters 0
TXT_UNICODE+="<0>"


// --------------------------------------------
// ------------ 2 - FIXED string ---------------
// --------------------------------------------

// Retrieve the simple string in the 'fixed string' variable
// If the simple string is longer than the size declared in the variable (50 in this example)
// the 'fixed string' variable is filled as much as possible according to its size and therefore,
// may be truncated
// If the simple string is shorter that the size of the fixed string
// the fixed string is filled with space characters.
sMyFixedString = TXT_SIMPLE



// Assign the edit control of the fixed string with the simple string
TXT_FIXED = sMyFixedString

// For a better view, the space characters that fill the string are replaced by "_"
// Calculate the size to fill
nLengthToComplete = 50-(Length(TXT_SIMPLE)+1)
// if the size to fill is greater than 0,
IF nLengthToComplete >0 THEN
// Fill with "_"
TXT_FIXED[[Length(TXT_SIMPLE)+1 ON nLengthToComplete]] = RepeatString("_",nLengthToComplete)
END

// --------------------------------------------
// ------------ 3 - ASCIIZ string -------------
// --------------------------------------------


sMyASCIIZString is string ASCIIZ on 50


// Retrieve the simple string in the 'ASCIIZ string' variable
// This type of string operates as the fixed string
// However, the ending character of the string is different.
// Indeed, this ASCIIZ string on 50 can contain 49 characters only,
// the last one being reserved for the ending character, the character 0
// Furthermore, the ASCIIZ string is not filled with space characters. Indeed, the character 0
// is used to mark the end of the string and it cannot be positioned anywhere in the string
sMyASCIIZString = TXT_SIMPLE

// To better view the string, the space characters are replaced by "_"
// and the character 0 that marks the end of the string is represented by "<0>"

// Replace the ending character 0 by "<0>"
TXT_ASCIIZ = sMyASCIIZString + "<0>"

// --------------------------------------------
// ------------ 4 - BUFFER TYPE -------------
// --------------------------------------------


// Update the result of the image (GIF or not?)
UPDResultGIF()

//-------------------------------------

// Syntax:
//UPDResultGIF ()
//
// This procedure is used to find out whether the image selected by the user is a GIF image or not
// A GIF image can be recognized by retrieving the first three bytes of the file,
// Indeed, for a GIF image, the first 3 characters are "GIF"

PROCEDURE UPDResultGIF()

// Declare a Buffer variable on 3 bytes.
// This variable is used to retrieve the first three characters
sMyImage is Buffer on 3

// Loads the content of the image file in the buffer
sMyImage = fLoadText(IMG_GIF..Value)

// Check the buffer retrieved (if it is a GIF image, the buffer must be equal to "GIF")
IF sMyImage [[ TO 3 ]] = "GIF" THEN
// It is a GIF image
STC_TC_RESULT1 = "The selected image is a GIF image."

ELSE
// It is not a GIF image
STC_TC_RESULT1 = "The selected image is not a GIF image."
END

//-----------------------------------------------------------------------
Illustrations, copies d'écran
none
none
Avis des utilisateurs
(Pour noter la ressource, cliquez sur Ecrire un avis)
Aucun avis ou commentaire ? Soyez le premier !