#1 Mon 10 May 2010 19:34
- jean94
- Participant assidu
- Date d'inscription: 13 Aug 2009
- Messages: 436
[Map Basic] Chaine de caractères
Bonjour à tous,
Je dois géocoder des adresses écrite en main libre (free form) dans un xls (transformer en .tab) avec des données géographique aussi en free form
Afin d'améliorer mon géocodage, (interopérabilité des deux adresses) j'essaie d'éliminer les caractères spéciaux de mais adresses pour les deux tables à l'aide d'un mbx.
Dans cet exemple purement fictif je voidrais que chacun des caratères (",",".","-","_","'" et " ") soit remplacé par "a"...éventuellement "a" sera remplacé par quelque chose du genre left$(strVar, len(strVar) - strCherchePos) + " " + right$(strVar, strCherchePos)
Or, mes caractère ne sont pas remplacé à la fin de ma loop...mais mes "print" sont afficher donc les chaines de caractères sont analysé
Voici mon code
Code:
Dim i_col_choix as smallint
Dim nom_col_choix as string
Dim strNomOri As String
Dim strNomModi as String
Dim strNomCol as string
Dim strnewtable as string
Dim strNewCol as string
Dim strVar as string
Dim strCherche as smallint
Dim strCherchePos as smallint
dim i as smallint
strnewtable = ReadControlValue(4)
strnewcol = ReadControlValue(10)
i_col_choix = ReadControlValue(7)
nom_col_choix = ColumnInfo(adresse,"col"+i_col_choix,COL_INFO_NAME)
strNomOri = adresse + "." + nom_col_choix
strNomModi = strnewtable + "." + strNewCol
print nom_col_choix
i = 0
Fetch First From adresse
Do While Not EOT(adresse)
'**************************************************************Étape 1
strvar = strNomOri
strcherche = InStr(1, strVar, ".")
if strcherche > 0 then
Do
strCherchePos = len(strVar)- strcherche + 1
strNomOri = "a"
strvar = strNomOri
strcherche = InStr(1, strVar, ".")
if strcherche = 0 then Exit Do
end if
Loop
end if
strcherche = InStr(1, strVar, "-")
if strcherche > 0 then
Do
strCherchePos = len(strVar)- strcherche + 1
strNomOri = "a"
strvar = strNomOri
strcherche = InStr(1, strVar, "-")
if strcherche = 0 then Exit Do
end if
Loop
end if
strcherche = InStr(1, strVar, ",")
if strcherche > 0 then
Do
strCherchePos = len(strVar)- strcherche + 1
strNomOri = "a"
strvar = strNomOri
strcherche = InStr(1, strVar, ",")
if strcherche = 0 then Exit Do
end if
Loop
end if
strcherche = InStr(1, strVar, "_")
if strcherche > 0 then
Do
strCherchePos = len(strVar)- strcherche + 1
strNomOri = "a"
strvar = strNomOri
strcherche = InStr(1, strVar, "_")
if strcherche = 0 then Exit Do
end if
Loop
end if
strcherche = InStr(1, strVar, "'")
if strcherche > 0 then
Do
strCherchePos = len(strVar)- strcherche + 1
strNomOri = "a"
strvar = strNomOri
strcherche = InStr(1, strVar, "'")
if strcherche = 0 then Exit Do
end if
Loop
end if
strcherche = InStr(1, strVar, " ")
if strcherche > 0 then
Do
strCherchePos = len(strVar)- strcherche + 1
strNomOri = "a"
strvar = strNomOri
strcherche = InStr(1, strVar, " ")
if strcherche = 0 then Exit Do
end if
Loop
end if
print i
i = i + 1
Fetch Next From adresse
Loop
print "terminé"Je veux éviter de passer par un update column pour l'instant
merci JF
Dernière modification par jean94 (Mon 10 May 2010 19:37)
Hors ligne
#2 Mon 10 May 2010 21:15
- jean94
- Participant assidu
- Date d'inscription: 13 Aug 2009
- Messages: 436
Re: [Map Basic] Chaine de caractères
Re :
J'ai trouvé une piste de solution. en fait j'ai réaliser que la valeur "a" est bel et bien attribuer à la variable "strNomOri" Par contre, la variable qui est un champ à une ligne données n'est pas mis-à-jour dans la table. Je crois qu'il faut passer par un update...
J'ai réaranger mes bouble de cette façon avec un update mais ma boucle tourne en rond et ne se termine pas
Code:
Dim i_col_choix as smallint
Dim nom_col_choix as string
Dim strNomOri As String
Dim strNomModi as String
Dim strNomCol as string
Dim strnewtable as string
Dim strNewCol as string
Dim strVar as string
Dim strCherche as smallint
Dim strCherchePos as smallint
dim i as smallint
strnewtable = ReadControlValue(4)
strnewcol = ReadControlValue(10)
i_col_choix = ReadControlValue(7)
nom_col_choix = ColumnInfo(adresse,"col"+i_col_choix,COL_INFO_NAME)
strNomOri = adresse + "." + nom_col_choix
strNomModi = strnewtable + "." + strNewCol
i = 1
Fetch First From adresse
Do While Not EOT(adresse)
'**************************************************************Étape 1
strvar = strNomOri
strcherche = InStr(1, strVar, ".")
if strcherche > 0 then
Do
strCherchePos = len(strVar)- strcherche + 1
update adresse
set nom_col_choix = "a"
where Rowid = i
strvar = strNomOri
strcherche = InStr(1, strVar, ".")
Loop until strcherche = 0
end if
Fetch Next From adresse
Loop
print "terminé"merci
JF
Hors ligne
#3 Tue 11 May 2010 16:52
- jean94
- Participant assidu
- Date d'inscription: 13 Aug 2009
- Messages: 436
Re: [Map Basic] Chaine de caractères
Bonjour a tous
Bon j'ai trouver une façon qui fonctionne mais je dois utilsier le update column
, or , j'ai un mini bug que j'aimerais que vous m'aidier à règler
Code:
Sub Stdr_adresse
Dim i_col_choix as smallint
Dim nom_col_choix as string
Dim strNomOri As String
Dim strNomModi as String
Dim strNomCol as string
Dim strnewtable as string
Dim strNewCol as string
Dim strVar as string
Dim strCherche as smallint
Dim strCherchePos as smallint
Dim ntime as integer
Dim nelapsed as integer
strnewtable = ReadControlValue(4)
strnewcol = ReadControlValue(10)
i_col_choix = ReadControlValue(7)
nom_col_choix = ColumnInfo(adresse,"col"+i_col_choix,COL_INFO_NAME)
strNomOri = adresse + "." + nom_col_choix
strNomModi = strnewtable + "." + strNewCol
CLS
nElapsed = Timer()
nTime = Timer()
Print (Timer()-nElapsed) & " Ajoute la colonne:"
Alter Table adresse ( add strnewcol Char(69) ) Interactive
Commit Table adresse
Set Table adresse FastEdit Off Undo On
Print "Table contains " & TableInfo(adresse, TAB_INFO_NROWS) & " records"
Set Table adresse FastEdit off Undo On
Print (Timer()-nElapsed) & " Table " & adresse & " complete:" & (Timer() - nTime)
nTime = Timer()
'**************************************************************
Set Table adresse FastEdit On Undo Off
Print (Timer()-nElapsed) & " ('-')"
nTime = Timer()
Update adresse Set strNewCol = StringReplace(Street2, "-", " ", 1)
Print (Timer()-nElapsed) & " seconds spent: " & (Timer() - nTime)
nTime = Timer()
Commit table adresse
Set Table adresse FastEdit Off Undo On
Alter Control 7 Title ""
end subEn fait, l'utilisateur choisi une colonne dans un listbox...cette valeur est ensuite envoyé à une varibale integer et cette variable est utiliser pour aller chercher le nom de la colonne plus tard dans "nom_col_choix". Dans ma fonction, ci-haut, si je mais "nom_col_choix" comme nom de colonne ma fonction ne fonctionne pas, le champ se met à jour en ajoutant le nom du champ (Street2) à toute les occurence. J'ai mit le véritable nom de la colonne (Street2) dans ma fonction, et voila tout fonctionne, or j'aimerais permettre à l'utilisateur de choisir lui même une colonne désirer d'ou le besoin de passer par une variable....comment faire?
Voici ou ma fonction est appelée
Code:
Update adresse Set strNewCol = StringReplace(Street2, "-", " ", 1)
Merci
JF
Dernière modification par jean94 (Tue 11 May 2010 17:10)
Hors ligne
#4 Tue 11 May 2010 20:04
- jean94
- Participant assidu
- Date d'inscription: 13 Aug 2009
- Messages: 436
Re: [Map Basic] Chaine de caractères
J'ai aussi essayer
Code:
Update adresse Set strNewCol = StringReplace(ColumnInfo(adresse,"col"+i_col_choix,COL_INFO_NAME), "-", " ", 1)
Mais MI renvoit toujours le titre du champ plutot que la valeur de la ligne
Hors ligne
#5 Tue 11 May 2010 20:16
- jean94
- Participant assidu
- Date d'inscription: 13 Aug 2009
- Messages: 436
Re: [Map Basic] Chaine de caractères
Bonjour après une journée de travail j'ai résolu mon problème
Il faut que la variable dans la fonction soit defini as "alias"
donc j'ai ajouter
Dim aChampFonction as alias
aChampFonction = nom_col_choix
Update adresse Set strNewCol = StringReplace(aChampFonction, "-", " ", 1)
Je suis sur que sa pourrait aider quelqun à l'avenir
A bientot
JF
Hors ligne
#6 Tue 11 May 2010 20:50
- Daniel
- Membre
- Lieu: Victoriaville, Québec
- Date d'inscription: 6 Sep 2005
- Messages: 2028
Re: [Map Basic] Chaine de caractères
Bonjour
C'est plaisant de voir que JF pose des questions et se répond lui-même... C'est ça être autodidacte??? ![]()
Bonne journée et merci du suivi
Daniel
De retour à la géomatique
Hors ligne
#7 Tue 11 May 2010 23:08
- Maurice
- Membre
- Lieu: Montpellier
- Date d'inscription: 5 Sep 2005
- Messages: 5331
Re: [Map Basic] Chaine de caractères
Bonsoir
On l'a déjà dit souvent ici mais il faudrait quasiment l'épingler en tête de forum:
avec MapBasic, pour manipuler des noms de colonne il faut définir les variables en "alias" ...
ps: d'ailleurs je l'ai fait ![]()
Hors ligne
#8 Wed 12 May 2010 21:04
- jean94
- Participant assidu
- Date d'inscription: 13 Aug 2009
- Messages: 436
Re: [Map Basic] Chaine de caractères
Je ne sais pas si ont peut dire autodidacte
mais avec de l'effort et de la recherche ont trouve toujours
Merci!
Hors ligne


