[prog] Ajout d'un Numberformat en 2.0

2006-03-15 Par sujet DAVID Jean-Claude - CETE Ouest/DU/AEH
Bonjour,
J'ai développé une appli en 1.1 au printemps 2004 (je n'ai plus refait de
StarBasic depuis), et aujourd'hui je regarde la migration en 2.02.rc4 et je
tombe sur la 1ère erreur ;-)
Soit... après quelques essais divers infructeux, je reprends une macro
exemple originale qui va bien (généralement) sur l'ajout de formats de
nombres, d'Andrew PITONYAK, et o stupeur elle bugue egalement ;-(
Je l'exécute en 1.1.5, elle fonctionne correctement.
Bon, j'ai fait un pas en avant, ce n'est pas que mon code qui lève l'erreur
mais également celui d'Andrew ;-) ça reconforte, mais cela ne me fait pas
beaucoup progresser...
L'erreur est une com.sun.star.uno.RuntimeException sur la ligne addNew à la
fin de la macro
Ais je loupé des choses sur l'évolution de la programmation en 2.0 ?
Qulequ'un a t'il une piste à explorer ?

D'avance merci
JCD

Sub Test
Dim i as Integer
i = FindCreateNumberFormatStyle( # ##0, ThisComponent)
MsgBox i = '  i  ', sbOkOnly, Titre_Appli
End Sub

'Author: Andrew Pitonyak
'email:   [EMAIL PROTECTED] 
Function FindCreateNumberFormatStyle ( sFormat As String, Optional doc,
Optional locale)
  
Dim oDocument As Object
Dim aLocale As New com.sun.star.lang.Locale
Dim oFormats As Object
Dim formatNum As Long 

  oDocument = IIf(IsMissing(doc), ThisComponent, doc)
  oFormats = oDocument.getNumberFormats()
  
  'If you choose to query on types, you need to use the type 
  'com.sun.star.util.NumberFormat.DATE
  'I could set the locale from values stored at
  'http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt 
  'http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html 
  'I use a NULL locale and let it use what ever it likes.
  'First, see if the number format exists
  If ( Not IsMissing(locale)) Then
aLocale = locale
  End If

  formatNum = oFormats.queryKey (sFormat, aLocale, TRUE)
  MsgBox Current Format number is   formatNum
  'If the number format does not exist then add it
  If (formatNum = -1) Then
formatNum = oFormats.addNew(sFormat, aLocale)
If (formatNum = -1) Then formatNum = 0
MsgBox New Format number is   formatNum
  End If
  FindCreateNumberFormatStyle = formatNum 
End Function

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: [prog] Ajout d'un Numberformat en 2.0

2006-03-15 Par sujet DAVID Jean-Claude - CETE Ouest/DU/AEH
Bon, je fais avancer mon Shmilblick...

En fait il apparait que c'est avec le getByKey que j'ai des problèmes. Vous
pouvez essayer le code ci dessous, qui indique que '# ##0' est différent de
'# ##0' !!!???... ;-

S1 est codé en dur comme '# ##0', S2 est affecté par le 3ème format de la
liste qui est égal à '# ##0'. Le test avec S1 ne fonctionne pas, celui avec
S2 fonctionne.

Une idée ?
JCD

Sub Test
Dim i as Integer
Dim NLS As New com.sun.star.lang.Locale
dim s1 as String 
dim s2 as String 
dim oFormats as Object 
dim oFormat as Object 

s1 = # ##0

oFormats = ThisComponent.getNumberFormats()
oFormat = oFormats.getByKey(3)
s2 = oFormat.FormatString()   

if (s1  s2) then
MsgBox s1  s2 (S1 = '  s1  ', s2 = '  s2  '),
sbOkOnly, Titre_Appli
MsgBox oFormat.FormatString =   oFormat.FormatString
MsgBox oFormat.Locale.Language =  
oFormat.Locale.Language
MsgBox oFormat.Locale.Country =   oFormat.Locale.Country
MsgBox oFormat.Locale.Variant =   oFormat.Locale.Variant
MsgBox oFormat.Type =   oFormat.Type '16 == Type =
NUMBER
MsgBox oFormat.Comment =   oFormat.Comment
else
MsgBox s1 = s2 (S1 = '  s1  ', s2 = '  s2  ')
end if

'Test 1 with s2 
i = oFormats.queryKey ( s2, NLS, TRUE)
MsgBox With s2, i = '  i  '

'Test with s1
NLS.Language = fr
NLS.Country = FR
i = oFormats.queryKey ( s1, NLS, TRUE)
MsgBox With s1, i = '  i  '

'Test 2 with s2 (with NLS Specified)
i = oFormats.queryKey ( s2, NLS, TRUE)
MsgBox With s2, i = '  i  '
End Sub

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: [prog] Ajout d'un Numberformat en 2.0

2006-03-15 Par sujet DAVID Jean-Claude - CETE Ouest/DU/AEH
Argh, merci beaucoup. J'en étais rendu à me préparer une boucle pour
afficher le code ascii caractère par caractère de la chaîne... ;-))
Bon, ben j'ai quand même perdu pas mal de temps avec ce p de séparateur
de milliers qui a donc changé en la V.1 et la V2.
A tous les deux on arrivera peut être à faire une perruque avec le tas au
pied du bureau ;-D

JCD

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]