Variables, Fonctions, Tableaux

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #251803 quote
    Bernard13
    Participant
    Average

    Bonjour,
    Je suis encore nul en codage et en traitement des tableaux, pouvez-vous valider ces deux observations :
    1   $T[1]= 3.14        DrawText(#$T[1]#, BarIndex , …   ne fonctionne pas
    a= $T[1]              DrawText(#a#, BarIndex … fonctionne et affiche 3.14

    2 Pourquoi cette boucle ne fonctionne pas:
    FOR i= 0 TO 5
    x= x + $T[i]
    NEXT

    x= $T[1] + $T[2] + $T[3] … fonctionne
    Une boucle WHILE ne marche pas non plus.

    Merci d’avance.

    #251808 quote
    Iván González
    Moderator
    Master

    Bonjour. Je confirme tes deux observations et je t’explique la raison.
    1. Utilisation de DRAWTEXT avec des tableaux:
    Tu ne peux pas utiliser directement $T[1] dans DRAWTEXT, car cette instruction attend une valeur scalaire et ne sait pas interpréter une référence de tableau.
    C’est pourquoi ton exemple :

    a = $T[1]
    DRAWTEXT(#a#, BarIndex, High)

    fonctionne, tandis que :

    DRAWTEXT(#$T[1]#, BarIndex, High)

    ne fonctionne pas.

    La solution est toujours d’assigner la valeur du tableau à une variable avant de l’afficher.

    2. Utilisation de boucles avec des tableaux.
    La boucle FOR fonctionne dans ProBuilder, mais il faut tenir compte de deux choses:
    * Initialiser la variable accumulatrice (x = 0 au début).
    * S’assurer que les éléments du tableau $T[i] existent et ont une valeur assignée.
    Un exemple correct serait :

    // Initialisation
    x = 0
    $T[0] = 0
    $T[1] = 1
    $T[2] = 2
    $T[3] = 3
    $T[4] = 4
    $T[5] = 5
    // Somme de tous les éléments
    FOR i = 0 TO 5 DO
       x = x + $T[i]
    NEXT
    
    return x
    robertogozzi and Bernard13 thanked this post
    #251810 quote
    Bernard13
    Participant
    Average

    Grand merci Ivan et Roberto (mon post d’hier) pour vos retours très rapides.

    robertogozzi thanked this post
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Variables, Fonctions, Tableaux


ProBuilder : Indicateurs & Outils Personnalisés

New Reply
Author
author-avatar
Bernard13 @bernard13 Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by Bernard13
4 months, 1 week ago.

Topic Details
Forum: ProBuilder : Indicateurs & Outils Personnalisés
Language: French
Started: 09/25/2025
Status: Active
Attachments: No files
Logo Logo
Loading...