❔ I need help urgent
I have a very annoying error yes I'm not so good at c# but I'm doing challenges for myself so it's giving me an error I want you to help me I'm breaking my head since yesterday I went to chat gpt bard but none of them solved my problem. this is the error: https://pastebin.com/jdUK1BWp
Pastebin
Error - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
73 Replies
Where's the code that the error's referencing?
so something on that line 46
noway.textorealdarich....
you have not instantiated, what is noway
?is variable public she it is located in another form
bro.
@sinfluxx sorry but the mistakes it is portuguese you can translate?
I can roughly translate, I'm a bit confused though as you have
NameOfDiv
, which is a Form
?
Then you're creating a new Form2
within NameOfDiv
, and calling that noway
, but then you're also creating the variable noway
again as a string
on line 26Then you're creating a new Form2 within NameOfDiv, and calling that noway, but then you're also creating the variable noway again as a string on line 26 No
this is another form already existing in it is the public variable
I already instantiated it to get its variable
But I don't know what's giving an error, it says it's giving an error on line 46 too
some simple debugging could give the solution instead of guessing
put a breakpoint there please
no way
it must have been my headache because I was breaking my head it's very confusing
do what @chaos_solo said and put a breakpoint there, so you can see what the variables are set to
how do you do this thing
I already found it
translated start debugging
click on the left of the line, so that a red circle appears, like below then run your program and it will stop (break) when it gets to that point in the code
Ok
in which variable?
on the line you're getting the exception
Ok
bro I just remembered that I left the program as administrator because of file creation @sinfluxx
I don't think that will be relevant to the error you're getting
i know I'm going to deactivate the business so I can see what the error is
what is? @sinfluxx
you see at the bottom, noway.textorealdarich is null?
yes
so because you're trying to find
.IndexOf("<body>")
within it, but it's null, it won't workbro
I will explain my program it is a program to make websites so easy by button
]
I'm struggling to follow everything completely, but it sounds to me like you're trying to access one Form from a different Form, and running into problems with that, also because you're declaring the Form again
I would have thought you should return what you need from the NameOfDiv form back to Form2 and let Form2 update itself
but I've never really used winforms
I'm not declaring Ok I just instantiated it to find the <body> </body> bro
that won't work the way you think it works
that's creating a whole new/unrelated instance of Form2
that's not why I need help either
too not
but i need help
I need help with this and with mistakes we learn
but is
this
add div a will add a division in the body and its name that will remain as a comment
but it's giving error
right, because
noway.textorealdarich
is not set to anything, as we saw abovehow not?
you've obviously not declared it properly somewhere, it's hard to say because we're just seeing little bits and pieces of your code
I'll show you all the code ok?
Pastebin
using System;using System.Collections.Generic;using System.Componen...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
this form 2
@sinfluxx
which you wants
then where do you launch NameOfDiv from?
Pastebin
using System;using System.Collections.Generic;using System.Componen...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
this is codeblock cs
line 95
and then your full NameOfDiv.cs?
why do this
when you could simply use
ReadAllText
Yes
I mean let us see it
to read the content inside the html file to richtextbox1
you can use ReadAllText avoiding ReadAllLines->string.join
that's what im saying
Pastebin
using System;using System.Collections.Generic;using System.Componen...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
bro I got confused calm down there
where this is?
which line?
i closed it i don't know
line 40 in Form2
if (File.Exists(Form1.nomedorarquivo))
{
codigo = richTextBox1.Text;
string[] linhas = File.ReadAllLines(Form1.nomedorarquivo);
string conteudo2 = string.Join(Environment.NewLine, linhas);
richTextBox1.Text = conteudo2;
textorealdarich = richTextBox1.Text;
}
this
yes
the original problem is still because of this as far as I can tell:
so it's for reading the file even explaining I didn't change the form of menu 1 I just put a panel and public variables etc then I put it like this and it's functional
so what can i do?
i was thinking of extracting data (settings) from the forms classes, but i'm not following that much
also, there is no full code to review
what you need?
more time, and probably the whole project
anyway yes i confirm i think you need a separate part of your project that deals with reading and saving data (also called isolation)
so that it can be used by forms
like I said I've never really dealt with winforms so I'm probably not best to advise on how things are done there but it does sound like you need to look into how to pass / return data between different forms
no problem but thank you for the help 🤝
winforms are very basic, instance just holds the data
so the raw method to do it is creating properties that the form fills and then the parent read those properties when it gets the control back
a modern way to do it would be using events
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.