블로그 이미지
안녕1999

카테고리

전체 (3067)
자바스크립트 (20)
안드로이드 (14)
WebGL (4)
변비 (17)
정치,경제 (35)
C언어,ARM (162)
컴퓨터(PC, Note Book, 윈.. (41)
전자회로, PCB (27)
유머,안웃긴,GIF,동영상 (118)
국부론60 (71)
모듈(PCB) (3)
건강 (2)
FreeCAD (25)
PADS (43)
퇴직,퇴사,구직,취업 활동 (3)
C# (86)
엑셀 (8)
워드 (0)
LabView (6)
레고 (30)
FPGA (0)
Total
Today
Yesterday

달력

« » 2024.5
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

공지사항

최근에 올라온 글

c# OnDropFile

C# / 2021. 4. 7. 08:38

c# OnDropFile
Form에서 AllowDrop=true로 변경하고,DragDrop, DragEnter 이벤트 핸들러 추가,
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.All;
} else
{
//String[] strGetFormats = e.Data.GetFormats();
//e.Effect = DragDropEffects.None;
}
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
// Assign the file names to a string array, in
  // case the user has selected multiple files.
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
try
{
int i; for (i = 0; i < files.Length; i++)
{
OnDropFile(files[i]);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
}

'C#' 카테고리의 다른 글

c# OnDropFile  (0) 2021.03.21
c# 파일 읽기, 쓰기  (0) 2021.03.21
오류 CS0106 이 항목의 'private' 한정자가 유효하지 않습니다.  (0) 2021.01.30
문자열 분리(나누기)  (0) 2020.12.19
기타등등  (0) 2020.12.05
Posted by 안녕1999
, |

c# OnDropFile

C# / 2021. 3. 21. 00:46

c# OnDropFile


Form에서 AllowDrop=true로 변경하고,

DragDrop, DragEnter 이벤트 핸들러 추가,


private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.All;
}
else
{
//String[] strGetFormats = e.Data.GetFormats();
//e.Effect = DragDropEffects.None;
}
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
// Assign the file names to a string array, in 
// case the user has selected multiple files.
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
try
{
int i;
for (i = 0; i < files.Length; i++)
{
OnDropFile(files[i]);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
}



'C#' 카테고리의 다른 글

c# OnDropFile  (0) 2021.04.07
c# 파일 읽기, 쓰기  (0) 2021.03.21
오류 CS0106 이 항목의 'private' 한정자가 유효하지 않습니다.  (0) 2021.01.30
문자열 분리(나누기)  (0) 2020.12.19
기타등등  (0) 2020.12.05
Posted by 안녕1999
, |

c# 파일 읽기, 쓰기

C# / 2021. 3. 21. 00:43

@@

c# 파일 읽기, 쓰기



static public string LoadFile(string file)
{
string ret = "";
try
{
ret = System.IO.File.ReadAllText(G.MakeFullPath(file), System.Text.Encoding.GetEncoding("ks_c_5601-1987"));
}
catch { }
return ret; 
}
static public bool FileWrite(string file, string s,int offset=0, bool bMakeBak = true)
{
byte[] data = Encoding.Default.GetBytes(s); 
return FileWrite(file, data, offset, data.Length, bMakeBak);
}
static public bool FileWrite(string file, byte[] data, int offset, int len, bool bMakeBak = true)
{
bool ret = false;
try
{
if (bMakeBak)
{
C.Rename_bak(file);
}
else
{
C.Unlink(file);
}
System.IO.FileStream f = new System.IO.FileStream(file, System.IO.FileMode.CreateNew);
f.Write(data, offset, len);
f.Close();
ret = true;
}
catch { }
return ret;
}



'C#' 카테고리의 다른 글

c# OnDropFile  (0) 2021.04.07
c# OnDropFile  (0) 2021.03.21
오류 CS0106 이 항목의 'private' 한정자가 유효하지 않습니다.  (0) 2021.01.30
문자열 분리(나누기)  (0) 2020.12.19
기타등등  (0) 2020.12.05
Posted by 안녕1999
, |

{ } 괄호의 짝이 안맞는 경우 발생
찾기가 쉽지 않을 수 도 있다.

'C#' 카테고리의 다른 글

c# OnDropFile  (0) 2021.03.21
c# 파일 읽기, 쓰기  (0) 2021.03.21
문자열 분리(나누기)  (0) 2020.12.19
기타등등  (0) 2020.12.05
원그리기  (0) 2020.12.05
Posted by 안녕1999
, |

문자열 분리(나누기)

C# / 2020. 12. 19. 23:45
문자열 분리(나누기)

공백문자(' ')로 문자열을 자르는 방법

string[] arrary_buf = str.Split(new string[] { " " }, System.StringSplitOptions.None);




		

		int str_cut(string s, ref string a, ref string b)//ret=bCuted
        {
            int i, bCuted=0;
            i = s.IndexOf(" ");
            if (i > 0)
            {
                a = s.Substring(0, i);
                b = s.Substring(i+1, s.Length-i-1);
                bCuted = 1;
            }
            else
            { 
                a = s;
                b = "";
            }
            return bCuted;
        }
        
        
        string a="", b="",c="",d="";
		str_cut(str,ref a, ref b);

'C#' 카테고리의 다른 글

c# 파일 읽기, 쓰기  (0) 2021.03.21
오류 CS0106 이 항목의 'private' 한정자가 유효하지 않습니다.  (0) 2021.01.30
기타등등  (0) 2020.12.05
원그리기  (0) 2020.12.05
Microsoft.Office.Interop.Excel.dll  (0) 2020.11.14
Posted by 안녕1999
, |

기타등등

C# / 2020. 12. 5. 23:45
C# double 변수 초기값 계산 오류
double d=7 / 3.0f - 9;   //-6.66666698455811
double d2 = 7 / 3.0f - 9;//-6.6666669845581055


WIN32에서 아래 코드 확인 결과,
	double d=7.0f / 3.0f - 9.0f;	//-6.6666666666667
	double d2=7 / 3.0f - 9;		//-6.6666666666667
	double d3=7 / 3 - 9;		//-7.0000000000000
	float f=7 / 3.0f - 9;		//-6.66667

인터넷 계산 결과 : 7 / 3 - 9 = -6.66666666667

원인 : C#에서 double은 숫자뒤에 'D'를 붙여줘야한다.
'D'를 붙이니, 값이 맞음.



S/N

HCOP:DEV:LANG PNG
HCOP:DEST1 'MMEM'
MMEM:NAME 'C:\Screenshots\PLOT1.PNG'
HCOP:DEST 'MMEM';:HCOP;MMEM:DATA?


변수 선언은 인라인될 수 있습니다.
How to resolve message IDE0018

string Func1(string s)
{
	string ret = "";	//<<====변수 선언은 인라인될 수 있습니다.
	Read("123", out ret);
	return ret;
}

원인 : (원래 느린) C#에서는 속도향상을 위해,
불필요한 코드는 최적화(?)하기위해
이런 체크기능을 추가한것으로 생각됨.
("사람인 니가 최적화 해라")

아래와 같이 함수의 인자에 string을 넣어주면, 이 경고는 사라짐.

string Func1(string s)
{
	Read("123", out string ret);
	return ret;
}

요약 : 쓸데없이 생성하지 말고, 함수의 인자값을 받아써라.

의견 : C언어 관점에서 봤을때,
C언어와 호환성이 점점 사라져간다.
C#이 아니라 D#이 맞을듯...

몇개 있을때는 상관없지만, 많아지면, 오류나 경고 메세지를 보기가 어렵다.
그래서 가능하면 없애주는것이 좋다.
VS는 오류메세지만 따로 보는 기능이 불편하다.
좌측하단의 오류, 경고, 메세지 를 마우스 클릭을 2회정도 해줘야,
각각 볼 수 있다.(불편)
그래서, 좀 귀찮더라도, 이런 메세지를 없애주는것이
코드 크기도 작아지고, 속도도 빨라진다.




				







ListView 깜빡임 문제 해결
아래 코드로 깜빡임 없이 동작함.
예) SetDoubleBuffer(ListView1);


	static public void SetDoubleBuffer(Control c,bool bSet=true)
	{
		c.GetType().GetProperty("DoubleBuffered",
					 System.Reflection.BindingFlags.Instance |
					 System.Reflection.BindingFlags.NonPublic)
					 .SetValue(c, bSet, null);
	}




byte[] 합치기 - 2개의 byte배열을 합치는 함수
	static public byte[] Memcat(byte[] a,int a_len,byte[]b,int b_len)
	{
		byte[] c = new byte[a_len + b_len];
		int len=0;
		if ((a != null) && (a_len > 0))
		{
			Array.Copy(c, 0, a, 0, a_len);
			len = a_len;
		}
		else { }
		if ((b != null) && (b_len > 0))
		{
			Array.Copy(c, len, b, 0, b_len);
			len += b_len;
		}
		else { }
		return c;
	}





Standing Wave Ratio (SWR)
전압 정재파비(VSWR: Voltage Standing Wave Ratio)
----------------------------
정재파(定在波, standing wave)
定:정할 정
在:있을 재
波:물결 파
반사계수, 혹은 S11, S22 등을 또 다르게 표현한 값
반사에 의해 생성되는 정재파 (Standing Wave)이 높이 비를 의미
정재파(Standing Wave)란, 
어떤 파동이 진행하다가 다른 매질을 만나서 
반사되어 나온 파동과 합쳐지면서 생기는 
고정된 파형을 의미한다.
반사량이 많을수록 고정된 정재파의 크기가 커진다.
VSWR은 반사가 거의 없는 경우는 1에 가깝고,
반사량이 늘어날수록 무한 대에 가까워진다.

측정방법
준비물 : 벡터 네트워크 아날라이져(NA), +15V 전원, SHORT,OPEN,LOAD 콘넥터
1) SWR메뉴에서, NA 케이블에 SHORT, OPEN, LOAD를 각각 연결해가면서, 캘리브레이션을 한다.
2) NA-입력:Test장비:출력-LOAD 순으로 연결후, 측정, 메모리
3) NA-출력:Test장비:입력-LOAD 순으로 연결후, 측정
20201117165002958.jpg
20201117165011102.jpg


리턴 로스(return loss. dB)
----------------------------
반사되어 돌아오는 양의 비율.
반사가 아예 없어, 돌아오는 양이 0인 경우, 무한대 dB.
반사가 매우 적은 경우, 돌아오는 양이 매우 적은 경우 10~50dB정도
반사가 매우 많은 경우, 돌아오는 양이 매우 많은 경우 10dB이하
(10dB기준은 설명을 위한 기준임)


VSWR은 작을수록 반사가 적다는 의미가 되고,
Return loss는 클수록 반사가 적다는 의미
예)
Return loss=10dB(VSWR은 2.0:1 이하,입력매칭이 비교적 잘된 경우)
Return loss=14dB(VSWR은 1.5:1 정도. 입력매칭이 거의 완벽)
Return loss= 5dB(VSWR은 3.5:1 안좋음)

반사계수
---------------
반사되는것이 없으면 0,
많으면 1에 가까워짐.


dBc (Decibel relative to carrier power level)
---------------------------------------------
dB : 상대적인 크기. Decibel(데시벨)
   예) -6dB(기준 신호보다 50% 작은 신호)
   예) +6dB(기준 신호보다 2배 큰 신호)

dBm : 측정전압의 크기.
   예) 10 dBm
   측정 기준에 따라 전력, 전압등으로 상호 변환이 가능하다.
   예) 600옴에서, 1dBm=0.8V, 10dBm=2.5V, 20dBm=7.75V
   예) 50~60옴에서, 10dBm=10mW, 20dBm=100mW, 30dBM=1W 

dBc : 캐리어주파수(중요 주파수)와 옆에 발생하는 기생주파수의 크기 차이
   예) 1MHz클럭 주파수 30dBm을 만들었더니,
       쓸모없는 500Hz 기생주파수가 -20dBm크기로 같이 나온다.
       이때 30-(-20)로 계산하여, 50dBc로 표시한다.





ipTime N8004 초기화 방법
CPU LED가 1초간격으로 깜빡이면
리셋버튼을 10초간 누르면,
CPU LED가 매우 빠르게 깜빡이면, 리셋버튼을 뗀다.



일관성 없는 액세스 가능성: 'b' 필드 형식이 'b' 필드보다 액세스하기 어렵습니다
=> enum타입은 public이 아니고, enum 타입의 변수는 public인 경우 발생.
   enum타입도 public으로 해준다.


	{
		HANDLE hDll;
		
		typedef BOOL (WINAPI *CHANGEWINDOWMESSAGEFILTER)(UINT message,DWORD dwFlag);
		CHANGEWINDOWMESSAGEFILTER ChangeWindowMessageFilter;
		
		hDll = LoadLibrary("USER32.DLL");
		
		ChangeWindowMessageFilter = (CHANGEWINDOWMESSAGEFILTER)GetProcAddress((HINSTANCE)hDll, "ChangeWindowMessageFilter");
		if(ChangeWindowMessageFilter)
		{
			#define MSGFLT_ADD 1
			ChangeWindowMessageFilter(WM_DROPFILES,MSGFLT_ADD);
			ChangeWindowMessageFilter(WM_COPYDATA,MSGFLT_ADD);
			ChangeWindowMessageFilter(0x0049,MSGFLT_ADD);
		}
		else{}
		DragAcceptFiles();
	}




GPIB22-WRITE="*RST;;"
COM5: W *OPC?
1
1
COM5: W SYSTem:ERRor?
-113,"Undefined header"
COM5: W SYSTem:ERRor?
-420,"Query UNTERMINATED"
COM5: W SYSTem:ERRor?
-420,"Query UNTERMINATED"
COM5: W SYSTem:ERRor?
+0,"No error"


*CLS;*OPC?





GPIB22-WRITE="*RST"
COM5: W *OPC?
1
1
COM5: W SYSTem:ERRor?
-113,"Undefined header"
COM5: W SYSTem:ERRor?
-420,"Query UNTERMINATED"
COM5: W SYSTem:ERRor?
-420,"Query UNTERMINATED"
COM5: W SYSTem:ERRor?
+0,"No error"


ProLOGIXS USB-GPIB
enables front panel operation(계측기에서 동작이 가능하도록. 매번 전송해야한다)
"++loc\r\n"



@@@윈도우 압축을 이용한 파일백업용 배치파일
- 폴더안의 파일을 압축하여, 날짜,시간별로 저장
- 윈도우 압축기능을 사용(별도 설치 프로그램 없음)
- 백업 서버에 복사(xcopy)
- 매시간 단위로 백업파일 생성
  예) 6시에 2번 실행해도, 압축파일은 1개만 생성됨(Update)

Backup.bat
-----------------------------------------------
set zip="압축파일이름-%date%-%time:~0,2%.zip"
powershell Compress-Archive -Path *.Lnk,*.xls,*.xlsx,*.bat,*.txt,*.atsln,*.sln -Update -DestinationPath %zip%

set dst="\\SERVER\내폴더\프로젝트1\"
xcopy /s/Y/D "%zip%" %dst%
explorer "%dst%"
REM pause






MEASure
 :VOLTage:DC? {|MIN|MAX|DEF},{|MIN|MAX|DEF}
 :VOLTage:DC:RATio? {|MIN|MAX|DEF},{|MIN|MAX|DEF}
 :VOLTage:AC? {|MIN|MAX|DEF},{|MIN|MAX|DEF}
 :CURRent:DC? {|MIN|MAX|DEF},{|MIN|MAX|DEF}
 :CURRent:AC? {|MIN|MAX|DEF},{|MIN|MAX|DEF}
 :RESistance? {|MIN|MAX|DEF},{|MIN|MAX|DEF}
 :FRESistance? {|MIN|MAX|DEF},{|MIN|MAX|DEF}
 :FREQuency? {|MIN|MAX|DEF},{|MIN|MAX|DEF}
 :PERiod? {|MIN|MAX|DEF},{|MIN|MAX|DEF}
 :CONTinuity?
 :DIODe?

MEASure:FREQuency?

MEASure:FREQuency 8322.75MHz	//안됨


 

'C#' 카테고리의 다른 글

오류 CS0106 이 항목의 'private' 한정자가 유효하지 않습니다.  (0) 2021.01.30
문자열 분리(나누기)  (0) 2020.12.19
원그리기  (0) 2020.12.05
Microsoft.Office.Interop.Excel.dll  (0) 2020.11.14
사칙연산 문제 생성  (0) 2020.11.07
Posted by 안녕1999
, |

원그리기

C# / 2020. 12. 5. 23:44
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
// Add reference for VISA-COM 5.9 Type Library
using Ivi.Visa.Interop;
using System.Diagnostics;
using System.Runtime.InteropServices;
//using Math.Util;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
public struct POINT
{
	public int x, y;
}
public class Test
{
	/*
	double 라디안 = 각도 * (float)(Math.PI / 180);
	double x2 = Math.Cos(라디안) * x1 - Math.Sin(라디안) * y1;
	double y2 = Math.Sin(라디안) * x1 + Math.Cos(라디안) * y1;
	*/
	[DllImport("user32.dll")]
	public static extern bool GetCursorPos(out POINT lpPoint);


	static int CirclePoint_n = 360 * 10;
	static double[] CirclePoint_x = new double[CirclePoint_n];
	static double[] CirclePoint_y = new double[CirclePoint_n];
	static bool bCreateCirclePoint;
	static void CreateCirclePoint()
	{
		int i;
		double ra = 0, x0, y0;
		x0 = 1;
		y0 = 0;
		for (i = 0; i < CirclePoint_n; i++)
		{
			double c, s;
			//x1=x*cos()-y*sin();
			//y1=x*sin()+y*cos();

			ra = Math.PI * 2 * i / CirclePoint_n;

			c = Math.Cos(ra);
			s = Math.Sin(ra);
			CirclePoint_x[i] = x0 * c - y0 * s;
			CirclePoint_y[i] = x0 * s + y0 * c;

			//G.DEBUG_puts(i.ToString()+"\t" + CirclePoint_x[i] + "\t" + CirclePoint_y[i]);
		}
		bCreateCirclePoint = true;

		//RotateMoveScale(x, y, n, ref x, ref y, 45,400,200,500);
	}
	//DrawPolygon(Pen, PointF[])
	//반지름이 1인 원의 좌표중 m개의 점만 얻는다
	//원의 좌표들을 미리 계산하여, RotateMoveScale하여 사용한다
	//7각형같은 다각형의 좌표로도 활용가능
	static void GetCirclePoint(ref double[] x, ref double[] y, int m)
	{
		int i, idx = 0, inc = CirclePoint_n / m;
		for (i = 0; i < m; i++)
		{
			x[i] = CirclePoint_x[idx];
			y[i] = CirclePoint_y[idx];
			idx += inc;
		}
	}



	static void RotateMoveScale(double[] x, double[] y, int n,
		ref double[] x2, ref double[] y2,
		double deg = 0,//deg=각도 0~360
		double dx = 0, double dy = 0,
		double Scale = 1)
	{
		int i;
		double ra, ix, iy;
		if (deg == 0)
		{
			if ((dx == 0) && (dy == 0))
			{
				if (Scale == 1)
				{
					for (i = 0; i < n; i++)
					{
						x2[i] = x[i];
						y2[i] = y[i];
					}
				}
				else
				{
					for (i = 0; i < n; i++)
					{
						x2[i] = x[i] * Scale;
						y2[i] = y[i] * Scale;
					}
				}
			}
			else
			{
				if (Scale == 1)
				{
					for (i = 0; i < n; i++)
					{
						x2[i] = x[i] + dx;
						y2[i] = y[i] + dy;
					}
				}
				else
				{
					for (i = 0; i < n; i++)
					{
						x2[i] = x[i] * Scale + dx;
						y2[i] = y[i] * Scale + dy;
					}
				}
			}
		}
		else
		{
			double c, s;
			ra = deg * (Math.PI / 180);
			c = Math.Cos(ra);
			s = Math.Sin(ra);
			if ((dx == 0) && (dy == 0))
			{
				if (Scale == 1)
				{
					for (i = 0; i < n; i++)
					{
						ix = x[i];//x와 x2가 같은 경우 문제가 됨
						iy = y[i];
						x2[i] = ix * c - iy * s;
						y2[i] = ix * s + iy * c;
					}
				}
				else
				{
					for (i = 0; i < n; i++)
					{
						ix = x[i];//x와 x2가 같은 경우 문제가 됨
						iy = y[i];
						x2[i] = (ix * c - iy * s) * Scale;
						y2[i] = (ix * s + iy * c) * Scale;
					}
				}
			}
			else
			{
				if (Scale == 1)
				{
					for (i = 0; i < n; i++)
					{
						ix = x[i];//x와 x2가 같은 경우 문제가 됨
						iy = y[i];
						x2[i] = ix * c - iy * s + dx;
						y2[i] = ix * s + iy * c + dy;
					}
				}
				else
				{
					for (i = 0; i < n; i++)
					{
						ix = x[i];//x와 x2가 같은 경우 문제가 됨
						iy = y[i];
						x2[i] = (ix * c - iy * s) * Scale + dx;
						y2[i] = (ix * s + iy * c) * Scale + dy;
					}
				}
			}
		}
	}



	static void DrawPolygon(Graphics g, double[] x, double[] y, int n)
	{
		PointF[] p = new PointF[n];
		int i;
		for (i = 0; i < n; i++)
		{
			p[i] = new PointF((float)x[i], (float)y[i]);
		}

		g.DrawPolygon(System.Drawing.Pens.LightGray, p);
	}
	static void Move(double[] x, double[] y, int n,
		ref double[] x2, ref double[] y2,
		double dx, double dy)
	{
		int i;
		for (i = 0; i < n; i++)
		{
			x2[i] = x[i] + dx;
			y2[i] = y[i] + dy;
		}
	}
	void Rotate(double[] x, double[] y, int n, double deg,//deg=각도 0~360
		ref double[] x2, ref double[] y2)
	{
		int i;
		double ra = deg * (Math.PI / 180),
			c, s;
		c = Math.Cos(ra);
		s = Math.Sin(ra);
		for (i = 0; i < n; i++)
		{
			x2[i] = x[i] * c - y[i] * s;
			y2[i] = x[i] * s + y[i] * c;
		}
	}



	//시작점,중심점으로 각도 계산
	static public double Get_deg_from_two_point(double ox, double oy,
		double x, double y)
	{
		return (180 / Math.PI * Math.Atan2(y - oy, x - ox));
	}
	static void test5()
	{
		double d;
		d = Get_deg_from_two_point(0, 0, 1, 0);//d=0
		G.DEBUG_puts_double("d", d);
		d = Get_deg_from_two_point(0, 0, 1, 1);//d=45
		G.DEBUG_puts_double("d", d);
		d = Get_deg_from_two_point(0, 0, 0, 1);//d=90
		G.DEBUG_puts_double("d", d);
		d = Get_deg_from_two_point(0, 0, -1, 1);//d=135
		G.DEBUG_puts_double("d", d);
		d = Get_deg_from_two_point(0, 0, -1, 0);//d=180
		G.DEBUG_puts_double("d", d);
		d = Get_deg_from_two_point(0, 0, -1, -1);//d=-135
		G.DEBUG_puts_double("d", d);
		d = Get_deg_from_two_point(0, 0, 1, -1);//d=-45
		G.DEBUG_puts_double("d", d);
	}


	//두점을 연결하는 직선의 방정식
	//y = ((y2 ? y1) / (x2 ? x1)) (x ? x1) + y1
	//두께가 d이고, 2점을 연결하는 직선1과, px,py에서 시작하는 수평선이 직선1과 만나는 지점구하기
	//(직선1과는 d/2만큼 떨어진 좌표이다.)
	//수평선은 직선1의 방정식에서 y값을 알고 있고, x좌표만 구하면 된다.(-d/2)



	static void Circle_r(Graphics g, double x1, double y1, double r)
	{

	}
	static void Circle_d(Graphics g, double x1, double y1, double d)
	{
		Circle_r(g, x1, y1, d / 2);
	}
	//두께가 d인 라인 그리기
	static void DrawWidthLine(Graphics g, double x1, double y1, double x2, double y2, double d)
	{
		Circle_d(g, x1, y1, d);
		Circle_d(g, x2, y2, d);

	}


	static public double angle;
	static public void DEBUG_Test_Paint(Form wnd, PaintEventArgs e)
	{
		Graphics g = e.Graphics;
		/*Font fnt = new Font("Arial", 10);

		// Draw a string on the PictureBox.
		g.DrawString("This is a diagonal line drawn on the control",
			fnt, System.Drawing.Brushes.Blue, new Point(30, 30));
		// Draw a line in the PictureBox.
		g.DrawLine(System.Drawing.Pens.Red, 10, 20,100, 150);*/
		if (bCreateCirclePoint == false)
		{
			CreateCirclePoint();
		}
		else { }

		POINT pt;
		GetCursorPos(out pt);

		int n = 8;
		double[] x2 = new double[n];
		double[] y2 = new double[n];

		GetCirclePoint(ref x2, ref y2, n);

		pt.x = 920;
		pt.y = 240;
		//Move(x, y, n,ref x2, ref y2,(double)pt.x, (double)pt.y);
		RotateMoveScale(x2, y2, n, ref x2, ref y2, angle, (double)pt.x, (double)pt.y, 5);
		//angle += 10;
		DrawPolygon(g, x2, y2, n);

		//DrawPolygon(g, x, y, n);


		//test5();
	}

	static public void DEBUG_Test3(Form wnd)
	{
		POINT p;
		GetCursorPos(out p);

	}
	static public void DEBUG_Test2(Form wnd)
	{
		Graphics g = wnd.CreateGraphics();
		CreateCirclePoint();
	}
	static public void DEBUG_Test4(Form wnd)
	{
		Graphics g = wnd.CreateGraphics();
		Rectangle r = new Rectangle(10, 20, 30, 40);

		POINT pt;
		Point p = new Point();
		GetCursorPos(out pt);
		p.X = pt.x;
		p.Y = pt.y;
		r.Location = p;
		r.Width = 10;
		r.Height = 2;

		System.Drawing.SolidBrush br = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
		g.FillRectangle(br, r);
	}
	static public void DEBUG_test1(Form wnd, int x, int y)
	{
		Graphics g = wnd.CreateGraphics();
		Pen pen = new Pen(Color.DarkSeaGreen);

		g.DrawArc(pen, x, y, 20, 20, 0, 270);
	}
	static public void DEBUG_test4(Form wnd, int x, int y)
	{
		Graphics g = wnd.CreateGraphics();
		Pen pen = new Pen(Color.DarkSeaGreen);

		g.DrawArc(pen, x, y, 20, 20, 0, 270);
	}
}

'C#' 카테고리의 다른 글

문자열 분리(나누기)  (0) 2020.12.19
기타등등  (0) 2020.12.05
Microsoft.Office.Interop.Excel.dll  (0) 2020.11.14
사칙연산 문제 생성  (0) 2020.11.07
소수점이하 쓸모없는 0을 제거하는 함수  (0) 2020.10.31
Posted by 안녕1999
, |

Microsoft.Office.Interop.Excel.dll

C# / 2020. 11. 14. 23:16
Microsoft.Office.Interop.Excel.dll
Microsoft.Office.Interop.Excel.zip
437.0 kB

'C#' 카테고리의 다른 글

기타등등  (0) 2020.12.05
원그리기  (0) 2020.12.05
사칙연산 문제 생성  (0) 2020.11.07
소수점이하 쓸모없는 0을 제거하는 함수  (0) 2020.10.31
StringBuilder 많은 문자열 합치기  (0) 2020.10.24
Posted by 안녕1999
, |

사칙연산 문제 생성

C# / 2020. 11. 7. 23:50
		void DEBUG_rnd_4_CAL()//사칙연산 문제 생성
		{
			Random rnd = new Random();
			string[] op= { "+", "-", "/", "*" };
			string s;
			int n=50,m;
			while (n > 0)
			{
				s = "";
				m= rnd.Next(3)+3;
				s = C.Ftoa2(rnd.Next(100) / (rnd.Next(10) + 1.0f)     - rnd.Next(50));
				while (m > 0)
				{
					s= s + " " + op[rnd.Next(op.Length)] +" "+ C.Ftoa2(rnd.Next(100) / (rnd.Next(10) + 1.0f) - rnd.Next(50));
					m--;
				}
				Console.WriteLine(s+",");
				n--;
			}
		}
		void DEBUG_test_Str_cal_with_brace()
		{
			string[] a = {
				"1 + 2 * (3 + 4)",
				"1 + 2 * 3",
				"111+1*2",
				//"48/2*(9+3)",
				"(2 + 3) * 4",
				"2 + (3 * 4)",
				"(6 / 2) * 3",
				"6 / (2 * 3)",
				"2 + 3 * 4",
				"6 / 2 * 3",
				"5 + 10 + 10",
				"7 / 3 - 9",
				//"7 / 3 - 9",
				"(123*456)+789 /123*1245",
				//------------------------
				"-5.14 * -7.5 * 56 + -29.4 / -24",
				"-23.5 + -2 * -6.43 * -23.2",
				"-38.29 + -3.56 / -4.5 * -37.33 + -8 + -34",
				"-32.78 * 22 - 18 / -20.75 - -22.33",
				"-29.67 + 54 + -31.17 + 20.33 * -35.67 - 15",
				"18.25 + -38.8 - -2.22 * -5.71 / 2.67 + -20",
				"-7.33 + -11.5 + -8.8 / -3.33 + -4.8 + -40.25",
				"-27 - -13.1 - -20.67 - -2.25 - 19",
				"-27.33 * -9.5 + -21.14 * -36.13",
				"-8.67 + -38.13 * -13.29 + -18.1 + 4.75 / -5.89",
				"-6.25 * 17 * 17.67 / -20.88 / -5.1 / -21",
				"-9.57 * -11.75 - -11.5 + -7.6",
				"3.4 * 0.57 * -40.5 - 4.14 - -24.25 * -6.75",
				"3.5 - -10.67 * -22.5 + -14 / -32.2",
				"-20.5 * -7 * -45 + -9.33",
				"-15.67 / -33 + -5.3 / -12",
				"45 / -4 + -6.75 - 8.83",
				"-25.67 / -11 - 4.11 / 41",
				"-6.63 + 0.71 - -28.67 / -17 - 1.5 * -7.75",
				"4.33 * -14.25 * -5.43 * -8.7 + -28",
				"-36.33 * -25.57 / -38.6 - -5.17 - 0.33 / 7.14",
				"-44.75 * -32.22 / -42.4 + -13 - -29.14 / -4.7",
				"-19.9 / -39.9 + -14.5 / -30.29 - 2 + 21",
				"-36.11 - -34.67 + 28 * -6.5",
				"-31.44 - 11 + -6.67 / 30.5",
				"-1 - -12 * -2.17 / 3 * -15.78",
				"-27.75 / -18.63 - -9.25 - -34 * -5 + -6.4",
				"5.5 + -36.4 + -0.83 * -7.33 - -33 * -42.89",
				"50 / 3.4 - -27.88 * -17.5 / -18",
				"35 - -32.22 / -28.5 + 2.5",
				"-3.33 + -29.33 * -1 * -23.4 + -42.25",
				"-37 * -0.14 / -31.4 / -5 + -25.6 / -19.33",
				"-16.6 + -29.33 - -19 + -19.83",
				"-29.5 - -19.22 * 6.5 * 5 + -7.38 / -22",
				"26.5 + -26.67 - 45.5 - 63 / -16.57",
				"3 + 4.56 / -22.75 / -40.33 / 1.4",
				"6 / 13 * -14 / 5.75 - -13.89",
				"1.5 + 1.75 / -34.56 * 2.9 - 1.44",
				"22.5 - -0.1 * -1.6 + -14.43 + 9.14",
				"-24.17 - -12 / -8.56 / -38.25 + -37.63 / -21.4",
				"-33.5 / -12.89 / -16 + -6.75 * -11.2 + -6.25",
				"15.75 + -3.75 - 65 - -39.14",
				"-38.88 / -17.78 - 2 * -0.75 - -41",
				"10 - 3.17 - -18.78 + 12 - -9",
				"-26.57 + -11.88 / -26 * -20.43 + -42.8 - 12",
				"29 * 2 * -15.5 + 4.17 * -36.4",
				"3.4 * -14.71 + -0.5 / -8 - -0.6 / 7",
				"-38.8 - -1.8 + -20.75 * -5.75 * 2.67",
				"61 - -11.5 * -14.25 * -35",
				"-20 * 0.2 + -19 + -23 / -6.25 * -14",
				//--------------------------------
				"-5.14 * (-7.5 * 56 + -29.4) / -24",
				"-23.5 + (-2 * -6.43) * -23.2",
				"(-38.29 + -3.56 / -4.5) * -37.33 + -8 + -34",
				"-32.78 * 22 - 18 / (-20.75 - -22.33)",
				"-29.67 + (54 + -31.17 + 20.33) * -35.67 - 15",
				"(18.25 + -38.8 - -2.22 * -5.71 / 2.67 + -20)",
				"(-7.33 + -11.5) + -8.8 / -3.33 + -4.8 + -40.25",
				"(-27 - -13.1 - -20.67) - -2.25 - 19",
				"-27.33 * (-9.5 + -21.14) * -36.13",
				"-8.67 + -38.13 * -13.29 + (-18.1 + 4.75 / -5.89)",
				"-6.25 * 17 * (17.67 / -20.88 / -5.1) / -21",
				"-9.57 * (-11.75 - -11.5) + -7.6",
				//--------------------------------
				"-5.14 * (-7.5 * (56 + -29.4)) / -24",
				"(-23.5 + (-2 * -6.43)) * -23.2",
				"((-38.29 + -3.56) / -4.5) * -37.33 + -8 + -34",
				"-32.78 * ((22 - 18) / (-20.75 - -22.33))",
				"((-29.67 + (54 + -31.17 + 20.33)) * -35.67) - 15",
				"(18.25 + (-38.8 - (-2.22 * (-5.71 / (2.67 + -20)))))",
				"(-7.33 + -11.5) + (-8.8 / -3.33) + (-4.8 + -40.25)",
				"((-27 - -13.1 - -20.67) - -2.25 - 19)",
				"(-27.33 * (-9.5 + -21.14) * -36.13)",
				"-8.67 + -38.13 * (-13.29 + (-18.1 + 4.75 / -5.89))",
				"((-6.25 * 17 )* (17.67 / -20.88 / -5.1)) / -21",
				"-9.57 * ((-11.75 - -11.5) + -7.6)"
			};
			double[] r =
			{
				1 + 2 * (3 + 4),
				1 + 2 * 3,
				111+1*2,
				//48/2.0D*(9+3),//나눗셈은 실수로 지정해주어야한다. double은 D
				(2 + 3) * 4,
				2 + (3 * 4),
				(6 / 2.0D) * 3,
				6.0D / (2 * 3),
				2 + 3 * 4,
				6 / 2.0D * 3,
				5 + 10 + 10,
				7.0D / 3D - 9.0D,
				//7 / 3 - 9,//정수를 넣어주면, 정수형으로 계산된다.
				(123*456)+789 /123.0D*1245,
				//------------------------
				-5.14D * -7.5D * 56D + -29.4D / -24D,
				-23.5D + -2 * -6.43D * -23.2,
				-38.29D + -3.56D / -4.5D * -37.33 + -8 + -34,
				-32.78D * 22 - 18D / -20.75D - -22.33,
				-29.67D + 54 + -31.17D + 20.33 * -35.67D - 15,
				18.25D + -38.8 - -2.22 * -5.71 / 2.67D + -20,
				-7.33D + -11.5 + -8.8 / -3.33 + -4.8 + -40.25,
				-27D - -13.1 - -20.67 - -2.25 - 19,
				-27.33D * -9.5 + -21.14 * -36.13,
				-8.67D + -38.13 * -13.29 + -18.1 + 4.75D / -5.89D,
				-6.25D * 17 * 17.67D / -20.88D / -5.1D / -21D,
				-9.57D * -11.75 - -11.5 + -7.6D,
				3.4D * 0.57 * -40.5 - 4.14 - -24.25 * -6.75D,
				3.5D - -10.67 * -22.5 + -14 / -32.2D,
				-20.5D * -7 * -45 + -9.33,
				-15.67D / -33 + -5.3 / -12D,
				45 / -4D + -6.75 - 8.83,
				-25.67 / -11D - 4.11 / 41,
				-6.63 + 0.71 - -28.67 / -17D - 1.5 * -7.75,
				4.33 * -14.25 * -5.43 * -8.7 + -28,
				-36.33 * -25.57 / -38.6 - -5.17 - 0.33 / 7.14,
				-44.75 * -32.22 / -42.4 + -13 - -29.14 / -4.7,
				-19.9 / -39.9 + -14.5 / -30.29 - 2 + 21,
				-36.11 - -34.67 + 28 * -6.5,
				-31.44 - 11 + -6.67 / 30.5,
				-1 - -12 * -2.17 / 3 * -15.78,
				-27.75 / -18.63 - -9.25 - -34 * -5 + -6.4,
				5.5 + -36.4 + -0.83 * -7.33 - -33 * -42.89,
				50 / 3.4 - -27.88 * -17.5 / -18,
				35 - -32.22 / -28.5 + 2.5,
				-3.33 + -29.33 * -1 * -23.4 + -42.25,
				-37 * -0.14 / -31.4 / -5 + -25.6 / -19.33,
				-16.6 + -29.33 - -19 + -19.83,
				-29.5 - -19.22 * 6.5 * 5 + -7.38 / -22,
				26.5 + -26.67 - 45.5 - 63 / -16.57,
				3 + 4.56 / -22.75 / -40.33 / 1.4,
				6 / 13D * -14 / 5.75D - -13.89,
				1.5D + 1.75D / -34.56D * 2.9 - 1.44D,
				22.5 - -0.1 * -1.6 + -14.43 + 9.14,
				-24.17 - -12 / -8.56D / -38.25D + -37.63 / -21.4D,
				-33.5 / -12.89D / -16D + -6.75 * -11.2 + -6.25,
				15.75 + -3.75 - 65 - -39.14,
				-38.88 / -17.78D - 2 * -0.75 - -41,
				10 - 3.17 - -18.78 + 12 - -9,
				-26.57 + -11.88 / -26D * -20.43 + -42.8 - 12,
				29 * 2 * -15.5 + 4.17 * -36.4,
				3.4 * -14.71 + -0.5 / -8D - -0.6 / 7D,
				-38.8 - -1.8 + -20.75 * -5.75 * 2.67,
				61 - -11.5 * -14.25 * -35,
				-20 * 0.2 + -19 + -23 / -6.25D * -14,
				//--------------------------------
				-5.14D * (-7.5D * 56D + -29.4D) / -24D,
				-23.5D + (-2 * -6.43) * -23.2,
				(-38.29D + -3.56 / -4.5D) * -37.33 + -8 + -34,
				-32.78D * 22 - 18 / (-20.75D - -22.33),
				-29.67D + (54 + -31.17 + 20.33) * -35.67 - 15,
				(18.25D + -38.8 - -2.22 * -5.71 / 2.67D + -20),
				(-7.33D + -11.5) + -8.8 / -3.33D + -4.8 + -40.25,
				(-27D - -13.1 - -20.67) - -2.25 - 19,
				-27.33D * (-9.5 + -21.14) * -36.13,
				-8.67D + -38.13 * -13.29 + (-18.1 + 4.75 / -5.89D),
				-6.25D * 17 * (17.67 / -20.88D / -5.1D) / -21D,
				-9.57D * (-11.75 - -11.5) + -7.6,
				//--------------------------------
				-5.14D * (-7.5D * (56D + -29.4D)) / -24D,
				(-23.5D + (-2 * -6.43)) * -23.2,
				((-38.29D + -3.56) / -4.5D) * -37.33 + -8 + -34,
				-32.78D * ((22 - 18) / (-20.75D - -22.33)),
				((-29.67D + (54 + -31.17 + 20.33)) * -35.67) - 15,
				(18.25D + (-38.8 - (-2.22 * (-5.71 / (2.67D + -20))))),
				(-7.33D + -11.5) + (-8.8 / -3.33D) + (-4.8 + -40.25),
				((-27D - -13.1 - -20.67) - -2.25 - 19),
				(-27.33D * (-9.5 + -21.14) * -36.13),
				-8.67D + -38.13 * (-13.29 + (-18.1 + 4.75 / -5.89D)),
				((-6.25D * 17 )* (17.67 / -20.88D / -5.1D)) / -21D,
				-9.57D * ((-11.75 - -11.5) + -7.6)
			};
			double d;
			int i,err_cnt=0, ok_cnt=0;
			//DEBUG_rnd_4_CAL();//사칙연산 문제 생성
			for (i = 0; i < a.Length; i++)
			{
				Console.WriteLine(a[i]);
				d = Str_cal_with_brace(a[i]);

				float f1, f2;
				f1 = ((float)d);
				f2 = ((float)r[i]);
				if (d != r[i])
				//if (((float)d) != ((float)r[i]))
				//if (f1 != f2)
				{
					//err
					err_cnt++;
					Console.WriteLine(a[i]);
					Console.WriteLine("ERR : " + a[i]+"="+C.Ftoa(r[i])+","+C.Ftoa(d));

					double d2 = 7 / 3.0f - 9;//-6.6666669845581055

				}
				else
				{
					Console.WriteLine("OK : " + a[i] + "=" + C.Ftoa(r[i]) + "," + C.Ftoa(d));
					ok_cnt++;
				}
			}
			Console.WriteLine("Total_cnt=" + a.Length.ToString());
			Console.WriteLine("ok_cnt="+ ok_cnt.ToString());
			Console.WriteLine("err_cnt=" + err_cnt.ToString());
		}
        
        
        
        
        
        
        int Find_and_Cal(double[]v,char[]op,int cnt,int i)//다음 숫자와 연산자 찾아서 계산
		{
			string msg = "";
			int find = -1, next;
			DEBUG_view_double_char(v, op, cnt);
			//다음 숫자와 연산자 찾기
			for (next = i + 1; next < cnt; next++)
			{
				//마지막 숫자는 연산자가 없다. 삭제된것이 아니면 ok
				if (op[next] !='D')//D=Delete
				{
					//find
					find = next;
					if (op[i] == '*')
					{
						v[i] = v[i] * v[next];
					}
					else if (op[i] == '/')
					{
						v[i] = v[i] / v[next];
					}
					else if (op[i] == '%')
					{
						v[i] = v[i] % v[next];
					}
					else if (op[i] == '+')
					{
						v[i] = v[i] + v[next];
					}
					else if (op[i] == '-')
					{
						v[i] = v[i] - v[next];
					}
					else
					{
						msg = "ERR : 알 수 없는 연산자";
					}
					//next 삭제
					op[i] = op[next];//다음연산자로 변경

					v[next] = 0;
					op[next] = 'D';//D=Delete

					DEBUG_view_double_char(v, op, cnt);

					i--;//다시한번 진행
					break;
				}
				else
				{
					//비어있는 슬롯.skip
				}
			}
			DEBUG_view_double_char(v, op, cnt);
			/*if(find==-1)
			{
				msg = "다음숫자를 못찾았습니다. or 계산 완료";
			}
			else { }*/
			return find;
		}
        bool HasCal(string s)//계산 수식이 있나?
		{
			bool ret = false;
			if (s != "")
			{
				ret = (s.IndexOf('+') >= 0) || (s.IndexOf('-') >= 0) ||
					(s.IndexOf('*') >= 0) || (s.IndexOf('/') >= 0) ||
					(s.IndexOf('%') >= 0);
			}
			else { }
			return ret;
		}
		double Str_cal_with_brace(string s)//괄호없는 문자열 사칙연산 문자열 수식 계산. s="1+2*3+4"
		{
			double ret = 0;
			if (s != "")
			{
				//수식이 있나?
				if (HasCal(s))
				{
					//수식(+-*/%) 있음
					bool bStart = true;
					int cnt = 0, i = 0, j, n = s.Length / 2 + 1, next, brace_cnt;
					double[] v = new double[n];
					char[] op = new char[n];
					string buf = "", msg = "", buf2 = "";
					v[0] = 0;
					s = s.Replace(" ", "");
					s = s.Replace("\t", "");
					s = s.Replace("\r", "");
					s = s.Replace("\n", "");
					while (i < s.Length)
					{
						if (s[i] == '(')
						{
							//괄호 처리. (앞에는 연산자
							i = C.Brace_cpy(s, i , out buf2);//'('을 발견하면 짝이 맞는 ')'이전까지만 복사한다.
							v[cnt] = Str_cal_with_brace(buf2);
							//다음 연산자 찾기
							//공백제거
							//i = C.Skip_space(s, i);
							if (i >= s.Length)
							{
								//마지막
								op[cnt] = ' ';
							}
							else
							{
								if ("+-/%*".IndexOf(s[i]) >= 0)
								{
									//연산자
									op[cnt] = s[i];
									i++;
								}
								else
								{
									//err
									msg = "ERR : +-/%* 연산자가 나올 차례입니다.";
									op[cnt] = '*';//곱셈연산자로 지정
								}
								bStart = true;
							}
							cnt++;//부호는 아직...
							DEBUG_view_double_char(v, op, cnt);
							buf = "";
						}
						else
						{
							//괄호 없음

							//"3-1"은? 첫번째 연산자, 부호 없음
							//"3--1"은? 첫번째 연산자, 부호 -
							//"-3-1"은? 첫번째 부호
							//"3-+1"은?
							if (bStart)//수식의 시작(부호만 올 수 있다 연산자가 앞에 올 수 없다
							{
								//부호 또는 숫자
								buf = buf + s[i];
								i++;
								bStart = false;
							}
							else
							{
								//연산자인가?
								//첫번째가 연산자(op)이고, 2번째 이후는 부호
								j = "+-/%*".IndexOf(s[i]);
								if ((j >= 0) &&
									(i != 0))//부호
								{
									//연산자
									//연산자.지금까지 저장한 값을 push
									v[cnt] = C.Atod(buf);
									op[cnt] = s[i];
									cnt++;
									DEBUG_view_double_char(v, op, cnt);
									buf = "";
									bStart = true;
								}
								else
								{
									//숫자
									buf = buf + s[i];
									bStart = false;
								}
								i++;
							}
							//DEBUG_puts("buf=" + buf);
						}
					}
					//마지막 숫자 넣기
					if (buf != "")
					{
						//push
						v[cnt] = C.Atod(buf);
						op[cnt] = ' ';//마지막은 연산자가 없다
						cnt++;
					}
					else { }
					DEBUG_view_double_char(v, op, cnt);

					//곱셈,나눗셈,나머지 부터 계산
					for (i = 0; i < cnt; i++)
					{
						if ((op[i] == '*') || (op[i] == '/') || (op[i] == '%'))
						{
							Find_and_Cal(v, op, cnt, i);//다음 숫자와 연산자 찾아서 계산
							i = -1;//다시 계산
						}
						else { }
					}
					DEBUG_view_double_char(v, op, cnt);

					//덧셈, 뺄셈 계산
					for (i = 0; i < cnt; i++)
					{
						if ((op[i] == '+') || (op[i] == '-'))
						{
							Find_and_Cal(v, op, cnt, i);//다음 숫자와 연산자 찾아서 계산
							i = -1;//다시 계산
						}
						else { }
					}
					DEBUG_view_double_char(v, op, cnt);
					ret = v[0];
				}
				else
				{
					//수식없음
				}
			}
			else { }
			return ret;
		}
Posted by 안녕1999
, |
	static public string cut_point_zero(string num)//실수형 숫자에서 우측 0을 제거한다.
	{
		int i= num.IndexOf('.');
		if (i >= 0)
		{
			int j;
			for(j=num.Length-1;j>i;j--)
			{
				if (num[j] == '0')
				{
				}
				else
				{
					break;
				}
			}
			if (j < num.Length)
			{
				if (i == j)//'.'위치라면.소수점이하가 모두 0
				{
					j--;
				}
				else { }
				num = num.Substring(0, j + 1);
			}
			else { }
		}
		else
		{ }
		return num;
	}
Posted by 안녕1999
, |

최근에 달린 댓글

글 보관함