Simple Task Solutions: Print Textbox and Replace Letters

  • Thread starter Thread starter i try
  • Start date Start date
  • Tags Tags
    Hello
Click For Summary

Discussion Overview

The discussion revolves around two programming tasks: one involves creating a pattern of numbers in a textbox, and the other focuses on replacing occurrences of the letter 'A' with 'X' in a given input sentence. The conversation includes attempts to provide code solutions and clarifications on programming languages used.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • Participants express a need for help with two programming tasks involving string manipulation and pattern generation.
  • One participant shares a code snippet written in Visual Basic, attempting to address the first task but indicates a lack of success.
  • Another participant suggests structuring the string creation into a routine and provides a sample code for generating the desired pattern.
  • There is a question about the programming language used, with some participants identifying it as Visual Basic and others initially questioning if it is Python.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach to solve the tasks, and there is uncertainty regarding the programming language being used.

Contextual Notes

Some code snippets provided may be incomplete or lack context, and there are unresolved issues regarding the functionality of the shared code.

i try
Messages
2
Reaction score
0
I need help in solving the two simple task, and I will be very grateful if you helped me.

1)Write a program that prints the textbox:


1
121
12321
1234321
123454321

2) Write a program that brings the input sentence.In this sentence instead of the letter A there is the letter X and show theat into the newly obtained string.

Thanks a lot!
 
Technology news on Phys.org
i try said:
I need help in solving the two simple task, and I will be very grateful if you helped me.

1)Write a program that prints the textbox:


1
121
12321
1234321
123454321

2) Write a program that brings the input sentence.In this sentence instead of the letter A there is the letter X and show theat into the newly obtained string.

Thanks a lot!

Hey i try and welcome to the forums.

Can you show us any code you've written along with any of your thoughts and what you've tried and thought about trying?
 
chiro said:
Hey i try and welcome to the forums.

Can you show us any code you've written along with any of your thoughts and what you've tried and thought about trying?

I tried to do that, but we do not succeed.

here code:


Public Class Form1
Dim m(10) As Char
Dim i, j, pr As Integer
Dim unos As Char
Dim postoji As Boolean


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Do While i < 11
postoji = False
unos = InputBox("unesi nesto")
ListBox1.Items.Add(unos)


For j = 1 To i - 1
If unos = m(j) Then
postoji = True
pr = j

End If
Next
Loop

If Not (postoji) Then
m(i) = unos
i = i + 1

i = i - 1

End If
 
I'm going to put your code in the tags first.

To do this you use the CODE tag with the square braces with /CODE at the end.

Code:
Public Class Form1
    Dim m(10) As Char
    Dim i, j, pr As Integer
    Dim unos As Char
    Dim postoji As Boolean    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Do While i < 11
            postoji = False
            unos = InputBox("unesi nesto")
            ListBox1.Items.Add(unos)            For j = 1 To i - 1
                If unos = m(j) Then
                    postoji = True
                    pr = j

                End If
            Next
        Loop

        If Not (postoji) Then
            m(i) = unos
            i = i + 1
        
            i = i - 1

        End If
End Form1
 
Is this Python?
 
OK, let's take it from the top.

The first thing you should realize that for creating the string is that you should decompose your string creation into just one routine that creates the string for the textbook (using an actual string object) and then assign this string to the value of the textbook.

For this function we should give the number of lines we want to create and then pass that to a function. Since this is a small routine, I'll write the routine and get your take on it.

Code:
Sub CalculateString(String s, ByVal n As Integer)
   s = ""
  
   dim x as integer
   dim i as integer
 
   for x = 1 to n
        for i = 1 to x
           s = s + Trim(Str(x))  
        end for
        for i = x-1 to 1
           s = s + Trim(Str(x))
        end for
        s = s + VbCrLf 
   end for
End Sub

I'm assuming that you pass the string by reference instead of by value and you could turn this into a function if you want to.
 
jtbell said:
Is this Python?

It's Visual Basic.
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
10
Views
5K
  • · Replies 13 ·
Replies
13
Views
4K
  • · Replies 93 ·
4
Replies
93
Views
22K
  • · Replies 6 ·
Replies
6
Views
14K